मुख्य सामग्री पर जाएँ
Skillpedia
API और सर्वर (backend)280k · #215

mysql-patterns

यह क्या करती है

यह टूल MySQL और MariaDB डेटाबेस बनाने और बेहतर करने में मदद करता है। इसमें टेबल व्यवस्थित करने, तेज़ indexes बनाने और तेज़ queries लिखने के पैटर्न दिए गए हैं।

कब इस्तेमाल करें

  • ✓टेबल का ढाँचा और indexes डिज़ाइन करते समय।
  • ✓यह जाँचने के लिए कि डेटाबेस queries धीमी क्यों चल रही हैं।
  • ✓आपके ऐप का डेटाबेस से कनेक्शन सेट करते समय।

Skill का लिंक

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/mysql-patterns/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/mysql-patterns/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरी users टेबल में नाम और बनने की तारीख से खोज को तेज़ करने के लिए index कैसे बनाऊँ?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह टूल कोड उदाहरणों और समझाइश के आधार पर सबसे अच्छे तरीके सुझाता है। यह दिखाता है कि टेबल कैसे परिभाषित करें, कौन सा data type चुनें, और ऐसी queries कैसे लिखें जो अच्छा प्रदर्शन दें।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

MySQL Patterns

Use this skill when working on MySQL or MariaDB schema design, migrations, slow-query investigation, queue-style transactions, connection pools, or production database configuration. Prefer exact version checks before applying a feature-specific pattern because MySQL and MariaDB have diverged in several SQL details.

Activation

  • Designing MySQL or MariaDB tables, indexes, and constraints
  • Reviewing migrations before they run on large production tables
  • Debugging slow queries, lock waits, deadlocks, or connection exhaustion
  • Adding keyset pagination, upserts, full-text search, JSON columns, or queues
  • Configuring application connection pools, read replicas, TLS, or slow logs

Version Check

Start by identifying the engine and version:

SELECT VERSION();
SHOW VARIABLES LIKE 'version_comment';

Keep MySQL and MariaDB guidance separate when syntax differs:

  • MySQL documents row aliases as the replacement for VALUES(col) in ON DUPLICATE KEY UPDATE; VALUES(col) is deprecated there.
  • MariaDB documents VALUES(col) as the supported way to reference inserted values in ON DUPLICATE KEY UPDATE; use it for cross-engine compatibility.
  • SKIP LOCKED is appropriate for queue-like work only. It skips locked rows and can return an inconsistent view, so do not use it for general accounting or integrity-sensitive reads.

Schema Defaults

CREATE TABLE orders (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    account_id BIGINT UNSIGNED NOT NULL,
    status VARCHAR(32) NOT NULL,
    total DECIMAL(15, 2) NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    deleted_at DATETIME NULL,
    PRIMARY KEY (id),
    KEY idx_orders_account_status_created (account_id, status, created_at),
    KEY idx_orders_active (account_id, deleted_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Default choices:

Use Case Prefer Avoid
Surrogate primary keys BIGINT UNSIGNED AUTO_INCREMENT INT for tables that can grow beyond 2B rows
UUID lookup keys BINARY(16) with conversion helpers VARCHAR(36) primary keys on hot tables
Money and exact quantities DECIMAL(p, s) FLOAT or DOUBLE
User-facing text utf8mb4 tables and indexes MySQL utf8 / utf8mb3 defaults
Application timestamps DATETIME with UTC managed by the app Assuming DATETIME stores time zone metadata
Soft deletes deleted_at DATETIME NULL plus scoped indexes Filtering soft-deleted rows without an index
Extensible status values lookup table or constrained VARCHAR ENUM when values change often

Indexing

Composite index order usually follows equality predicates first, then range or sort columns:

CREATE INDEX idx_orders_account_status_created
    ON orders (account_id, status, created_at);

SELECT id, total
FROM orders
WHERE account_id = ?
  AND status = 'pending'
  AND created_at >= ?
ORDER BY created_at DESC
LIMIT 50;

Use EXPLAIN before adding or changing an index:

EXPLAIN
SELECT id, total
FROM orders
WHERE account_id = 123 AND status = 'pending'
ORDER BY created_at DESC
LIMIT 50;

Signals to investigate:

Field Risk Signal
type ALL on a large table
key NULL when a selective predicate exists
rows Very high row estimate for an interactive path
Extra Using temporary, Using filesort, or broad Using where

Avoid adding indexes blindly. Each index increases write cost, migration time, backup size, and buffer-pool pressure.

Query Patterns

Upsert

Cross-engine-compatible form:

INSERT INTO user_settings (user_id, setting_key, setting_value)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE
    setting_value = VALUES(setting_value),
    updated_at = CURRENT_TIMESTAMP;

MySQL row-alias form:

INSERT INTO user_settings (user_id, setting_key, setting_value)
VALUES (?, ?, ?) AS new
ON DUPLICATE KEY UPDATE
    setting_value = new.setting_value,
    updated_at = CURRENT_TIMESTAMP;

Use the row-alias form only after confirming the target is MySQL. Use VALUES(col) for MariaDB or mixed MySQL/MariaDB fleets.

Keyset Pagination

SELECT id, name, created_at
FROM products
WHERE (created_at, id) < (?, ?)
ORDER BY created_at DESC, id DESC
LIMIT 50;

…

अक्सर पूछे जाने वाले सवाल

इस संदर्भ में 'patterns' क्या होते हैं?

Patterns डेटाबेस की आम समस्याओं के लिए आज़माए हुए और अनुशंसित हल होते हैं, जैसे डेटा को व्यवस्थित करना या खोज को तेज़ करना।

मुझे MySQL/MariaDB के version की चिंता क्यों करनी चाहिए?

अलग-अलग versions SQL कमांड को थोड़ा अलग तरीके से समझ सकते हैं, इसलिए सही पैटर्न लगाने के लिए आपको पता होना चाहिए कि आप कौन सा version इस्तेमाल कर रहे हैं।

'keyset pagination' क्या है?

यह डेटा को पेज-दर-पेज लाने का एक कुशल तरीका है, खासकर बड़ी टेबल पर। यह 'offset' वाले पारंपरिक तरीके से तेज़ होता है।

जानकारी

लेखक का मूल विवरण

MySQL and MariaDB schema, query, indexing, transaction, replication, and connection-pool patterns for production backends. Use when designing MySQL or MariaDB schemas and indexes, or when a query, transaction, or replica lags.

repo: affaan-m/ECC

लोकप्रियता

GitHub स्टार
280k
रैंकिंग में स्थान
#215
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

accessibility

280k

यह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।

डिज़ाइनइंटरफ़ेस (UI/UX)

agent-architecture-audit

280k

यह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।

AI और एजेंटएजेंट

agent-eval

280k

यह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।

AI और एजेंटएजेंट

agent-harness-construction

280k

यह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।

AI और एजेंटएजेंट

मिलती-जुलती skills