mysql-patterns
ما الذي تفعله
تساعدك هذه المهارة على إنشاء قواعد بيانات MySQL وMariaDB وتحسينها. توفر أنماطًا لتنظيم الجداول، وإنشاء فهارس فعّالة، وكتابة استعلامات سريعة.
متى تستخدمها
- ✓عندما تصمم بنية الجداول والفهارس.
- ✓عندما تبحث عن سبب بطء استعلامات قاعدة البيانات.
- ✓عندما تضبط اتصال تطبيقك بقاعدة البيانات.
رابط المهارة
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/mysql-patterns/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“كيف أنشئ فهرسًا لتسريع البحث بالاسم وتاريخ الإنشاء في جدول المستخدمين لديّ؟”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تقترح المهارة أفضل الممارسات استنادًا إلى أمثلة برمجية وشروح. وتوضح كيفية تعريف الجداول، وأنواع البيانات التي يجب استخدامها، وكيفية كتابة استعلامات تعمل بكفاءة.
المحتوى التقني (ملف 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)inON DUPLICATE KEY UPDATE;VALUES(col)is deprecated there. - MariaDB documents
VALUES(col)as the supported way to reference inserted values inON DUPLICATE KEY UPDATE; use it for cross-engine compatibility. SKIP LOCKEDis 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;
…
الأسئلة الشائعة
ماذا تعني «الأنماط» في هذا السياق؟
الأنماط حلول مجرّبة ومعتمدة لمشكلات شائعة في استخدام قواعد البيانات، مثل تنظيم البيانات أو تسريع عمليات البحث.
لماذا أهتم بإصدار MySQL/MariaDB؟
تختلف الإصدارات قليلًا في طريقة فهمها لأوامر SQL، لذا من المهم معرفة الإصدار الذي تستخدمه لتطبيق النمط الصحيح.
ما هو «الترقيم بالمفاتيح» (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
التعليقات
- …
المزيد من المهارات من هذا المستودع
accessibility
280kيساعد وكيلك على بناء واجهات يستطيع الجميع استعمالها، ويضمن عمل المواقع والتطبيقات جيدًا لذوي الإعاقة، كالمكفوفين وذوي الحركة المحدودة.
agent-architecture-audit
280kيتأكد وكيلك من أن كل شيء يعمل بشكل صحيح، ويجد مشكلات أنظمة الذكاء الاصطناعي ويصلحها، ليؤدي كما هو متوقع.
agent-eval
280kيساعد وكيلك على مقارنة أدوات البرمجة بالذكاء الاصطناعي المختلفة، ويقيس أيها أسرع وأرخص وأكثر موثوقية لمهام محددة.
agent-harness-construction
280kيساعد وكيلك على فهم طريقة إنجاز المهام بشكل أفضل، عبر تحسين الأدوات والتعليمات التي يستعملها لزيادة فرص نجاحه.
مهارات مشابهة
shopify
260kيتيح لوكيلك قراءة بيانات متجر Shopify وتحديثها، مثل المنتجات والمخزون والطلبات والعملاء، عبر واجهة Shopify GraphQL API.
rest-graphql-debug
260kيساعد وكيلك على معرفة سبب فشل استدعاء API من نوع REST أو GraphQL، بفحص الاتصال وتسجيل الدخول وصيغة الطلب والرد طبقة بعد طبقة.
har-derived-api-client
260kيساعد وكيلك على تسجيل حركة الشبكة لموقع إلكتروني مرة واحدة، ثم بناء عميل API مباشر له، فلا يعود إلى النقر في الصفحة في كل مرة.