mariadb-select

Documents MariaDB-specific SELECT syntax, optimizer hints, locking, and file output behavior.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-select-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-select
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/statements/mariadb-select
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-select-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Standard SQL knowledge is not enough to write correct SELECT statements for MariaDB: its optimizer hints, LIMIT extensions, locking modifiers, and file-output clauses differ from both the SQL standard and other databases, and LLMs frequently generate wrong or legacy forms. This Skill provides the exact MariaDB delta so generated or reviewed SELECT statements are syntactically valid and idiomatic. ## Core Features & Use Cases - Optimizer hints: Covers the /*+ ... */ hint-comment form (MAX_EXECUTION_TIME, JOIN_ORDER, JOIN_FIXED_ORDER, JOIN_PREFIX, JOIN_SUFFIX) and legacy keyword hints like STRAIGHT_JOIN and SQL_CALC_FOUND_ROWS, including which to avoid. - Pagination and locking: Documents LIMIT comma-form vs OFFSET keyword, OFFSET ... FETCH ... WITH TIES, ROWS EXAMINED, and FOR UPDATE / LOCK IN SHARE MODE with WAIT, NOWAIT, and SKIP LOCKED for worker-queue patterns. - File output and temporal queries: Explains SELECT INTO OUTFILE, INTO DUMPFILE, INTO @var, WITH ROLLUP, PARTITION pruning, and FOR SYSTEM_TIME on system-versioned tables. - Use Case: When asked to write a paginated queue-consumer query for MariaDB, produce SELECT ... FOR UPDATE SKIP LOCKED with LIMIT ... OFFSET instead of the non-portable or blocking forms an LLM would otherwise emit. ## Quick Start Ask the AI to write or review a MariaDB SELECT statement, such as a paginated query with row locking or an export using INTO OUTFILE, and it will apply the MariaDB-specific syntax from this Skill.

Frequently Asked Questions about mariadb-select

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a paginated SELECT query in MariaDB?▼

MariaDB supports three pagination forms: LIMIT offset, count (comma form), LIMIT count OFFSET offset, and standard OFFSET ... FETCH NEXT ... ROWS ONLY since 10.6. The LIMIT count OFFSET offset form is recommended because the comma form reverses the argument order used by most other databases.

How do I use SKIP LOCKED for a worker queue in MariaDB?▼

Append FOR UPDATE SKIP LOCKED to the SELECT inside a transaction so concurrent workers skip rows locked by others instead of blocking. It is InnoDB-only and silently ignored on other storage engines, and it implies NOWAIT behavior.

Does MariaDB support optimizer hints in SELECT statements?▼

Yes, MariaDB supports the /*+ ... */ hint-comment form placed immediately after SELECT, with hints like MAX_EXECUTION_TIME, JOIN_ORDER, JOIN_PREFIX, JOIN_FIXED_ORDER, and JOIN_SUFFIX available since 12.0. Legacy keyword hints such as STRAIGHT_JOIN and SQL_SMALL_RESULT sit between SELECT and the column list.

Why does SELECT INTO OUTFILE fail in MariaDB?▼

INTO OUTFILE fails if the target file already exists, since it never overwrites, or if the user lacks the FILE privilege. The path must also satisfy the secure_file_priv system variable, and the filename must be a string literal rather than a variable.

Can I use ORDER BY with WITH ROLLUP in MariaDB?▼

No, WITH ROLLUP cannot be combined with ORDER BY in MariaDB. Use ASC or DESC on the GROUP BY columns to control ordering, and note that super-aggregate rows always appear last and that LIMIT applies after rollup rows are added.

How do I query historical data with FOR SYSTEM_TIME in MariaDB?▼

On tables created WITH SYSTEM VERSIONING, add FOR SYSTEM_TIME AS OF, BETWEEN, FROM ... TO, or ALL immediately after the table name. The system_versioning_asof variable can also apply a default AS OF point to every query in the session.