Install
openclaw skills install alibabacloud-polardbx-sqlDesign partition schemes, select partition keys, create GSI, and write SQL for PolarDB-X 2.0 Enterprise Edition AUTO mode databases, handling PolarDB-X vs MySQL differences (partitioned tables, GSI, CCI, Sequence, table groups, TTL, pagination, etc.). Use when designing partition schemes, selecting partition keys, converting single tables to partitioned tables, creating GSI/CCI indexes, writing or migrating SQL for PolarDB-X, or diagnosing slow queries on PolarDB-X. Triggers: "PolarDB-X SQL", "PolarDB-X create table", "partitioned table", "partition design", "partition scheme", "partition key", "GSI", "CCI", "Sequence", "MySQL migrate to PolarDB-X", "PolarDB-X compatibility", "single table to partitioned table", "convert to partitioned table", "large table", "table sharding", "distributed table", "AUTO mode", "pagination query", "Keyset pagination", "Range partition", "auto add partition", "PolarDB-X slow query", "full-shard scan"
openclaw skills install alibabacloud-polardbx-sqlWrite, review, and adapt SQL for PolarDB-X 2.0 Enterprise Edition (Distributed Edition) AUTO mode databases, avoiding the "runs on MySQL but fails on PolarDB-X" problem.
Architecture: PolarDB-X 2.0 Enterprise Edition (CN compute nodes + DN storage nodes + GMS metadata service + CDC log nodes) + AUTO mode database
Scope:
Not applicable to:
Key difference between AUTO mode and DRDS mode: AUTO mode uses MySQL-compatible PARTITION BY syntax to define partitions, while DRDS mode uses the legacy dbpartition/tbpartition syntax. Verify the database mode with:
SHOW CREATE DATABASE db_name;
-- Output containing MODE = 'auto' indicates AUTO mode
Connect to a PolarDB-X instance via a MySQL-compatible client:
mysql -h <host> -P <port> -u <user> -p<password> -D <database>
Supported clients: MySQL CLI, MySQL Workbench, DBeaver, Navicat, or any MySQL-compatible client.
IMPORTANT: Parameter Confirmation — Before executing any command or API call, ALL user-customizable parameters (e.g., RegionId, instance names, CIDR blocks, passwords, domain names, resource specifications, etc.) MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.
Configurable parameters for this skill:
| Parameter Name | Required/Optional | Description | Default Value |
|---|---|---|---|
| host | Required | PolarDB-X instance connection address | None |
| port | Required | PolarDB-X instance port | 3306 |
| user | Required | Database username | None |
| password | Required | Database password | None |
| database | Required | Target database name | None |
SELECT VERSION(); to determine the instance type:
TDDL with version > 5.4.12 (e.g., 5.7.25-TDDL-5.4.19-20251031) -> 2.0 Enterprise Edition (Distributed Edition), this skill applies. Parse the Enterprise Edition version number (e.g., 5.4.19).TDDL with version <= 5.4.12 (e.g., 5.6.29-TDDL-5.4.12-16327949) -> DRDS 1.0. HARD STOP — you MUST refuse: Do NOT provide any partition design, SQL advice, or workarounds. Respond only with: "This skill covers PolarDB-X 2.0 Enterprise Edition AUTO mode only. Your instance is DRDS 1.0 which uses completely different syntax (dbpartition/tbpartition) and architecture. Please consult DRDS 1.0 documentation or upgrade to PolarDB-X 2.0." Then stop. Do NOT continue even if the user insists.X-Cluster (e.g., 8.0.32-X-Cluster-8.4.20-20251017) -> 2.0 Standard Edition. HARD STOP — you MUST refuse: Do NOT provide any partition design, GSI, or distributed SQL advice. Respond only with: "Your instance is PolarDB-X 2.0 Standard Edition (100% MySQL compatible, no distributed partitioning). Please use the polardbx-standard skill instead." Then stop. Do NOT continue even if the user insists.SHOW CREATE DATABASE db_name; to verify AUTO mode (MODE = 'auto').BROADCAST (fully replicated to every DN, enables local JOIN pushdown). This is the recommended choice when JOINs are involved.BROADCAST and SINGLE are acceptable. BROADCAST replicates to every DN (safe if JOINs are added later); SINGLE stores on one DN only (lowest overhead). Either is fine — do NOT insist on one over the other.PARTITION BY KEY(...) PARTITIONS N — see gsi.md for full syntax.KEY or HASH partitioning instead of MySQL's AUTO_INCREMENT primary key write hotspot.EXPLAIN to view the logical execution plan.EXPLAIN EXECUTE to view the physical execution plan pushed down to DN.EXPLAIN SHARDING to view shard scan details and check for full-shard scans.EXPLAIN ANALYZE to actually execute and collect runtime statistics.SINGLE), Broadcast table (BROADCAST), Partitioned table (default); choose based on data volume and access patterns.-- ✅ Correct: GSI with PARTITION BY clause
GLOBAL INDEX g_i_seller(seller_id) PARTITION BY KEY(seller_id) PARTITIONS 16
CLUSTERED INDEX cg_i_buyer(buyer_id) PARTITION BY KEY(buyer_id) PARTITIONS 16
-- ❌ Wrong: Missing PARTITION BY (this is NOT MySQL INDEX syntax)
GLOBAL INDEX gsi_seller(seller_id)
Classic partition design — order table: Candidates are order_id (PK) and buyer_id. Comprehensive analysis: order_id has the highest cardinality (unique per row), zero hotspot risk, PK status, and semantically high query frequency (order detail/status/payment lookups); buyer_id has high buyer-dimension query ratio but potential distribution skew (some buyers generate far more orders). Conclusion: order_id as partition key + Clustered GSI on buyer_id.CLUSTERED COLUMNAR INDEX.NEW SEQUENCE (5.4.14+), distributed alternative to AUTO_INCREMENT.INSPECT INDEX to periodically clean up redundant GSIs. Every GSI must have its own PARTITION BY KEY(...) PARTITIONS N clause; never write bare GLOBAL INDEX idx(col) without PARTITION BY.:=, etc.EXPLAIN SHARDING and EXPLAIN ANALYZE.LIMIT M, N deep pagination (cost O(M+N), even larger in distributed systems); record the sort value of the last row in each batch as the WHERE condition for the next batch; when sort columns may have duplicates, use (sort_column, id) tuple comparison; ensure appropriate composite indexes on sort columns.ALTER TABLE ... MODIFY TTL SET syntax (with multiple parameters like TTL_EXPR, TTL_PART_INTERVAL, ARCHIVE_TYPE, ARCHIVE_TABLE_PRE_ALLOCATE, etc.) to configure automatic partition pre-creation. This syntax is NOT standard SQL and cannot be guessed — you MUST read references/auto-add-range-parts.md for the exact SQL syntax before generating any auto-add partition configuration. Requires version 5.4.20+.| Reference | Description |
|---|---|
| references/create-table.md | CREATE TABLE syntax, table types (single/broadcast/partitioned), partition strategies, secondary partitions, partition management |
| references/partition-design-best-practice.md | Partition design best practices: partition key/GSI/algorithm/count selection, three-step migration, complete examples |
| references/primary-key-unique-key.md | Primary key and unique key Global/Local classification, rules, risks, and recommendations |
| references/gsi.md | Global Secondary Index GSI/UGSI/Clustered GSI creation, querying, and limitations |
| references/cci.md | Clustered Columnar Index CCI creation, usage, and applicable scenarios |
| references/sequence.md | Sequence types (NEW/GROUP/SIMPLE/TIME), creation and usage |
| references/transactions.md | Distributed transaction model, isolation levels, and considerations |
| references/mysql-compatibility-notes.md | MySQL vs PolarDB-X compatibility differences and development limitations |
| references/explain.md | EXPLAIN command variants and execution plan diagnostics |
| references/ttl-table.md | TTL table definition, cold data archiving, and cleanup scheduling |
| references/online-ddl.md | Online DDL assessment, lock-free execution strategy, long transaction checks, DMS lock-free changes |
| references/pagination-best-practice.md | Efficient pagination: Keyset pagination, per-shard traversal, index requirements, Java examples |
| references/auto-add-range-parts.md | Range partition auto-add: TTL-based partition pre-creation, first/second level configuration, management commands |
| references/cli-installation-guide.md | Alibaba Cloud CLI installation guide |