@mytechtoday/augment-extensions 0.1.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +614 -39
- package/augment-extensions/coding-standards/bash/README.md +196 -0
- package/augment-extensions/coding-standards/bash/module.json +163 -0
- package/augment-extensions/coding-standards/bash/rules/naming-conventions.md +336 -0
- package/augment-extensions/coding-standards/bash/rules/universal-standards.md +289 -0
- package/augment-extensions/coding-standards/css/README.md +40 -0
- package/augment-extensions/coding-standards/css/examples/css-examples.css +550 -0
- package/augment-extensions/coding-standards/css/module.json +44 -0
- package/augment-extensions/coding-standards/css/rules/css-modern-features.md +448 -0
- package/augment-extensions/coding-standards/css/rules/css-standards.md +492 -0
- package/augment-extensions/coding-standards/html/README.md +40 -0
- package/augment-extensions/coding-standards/html/examples/html-examples.html +267 -0
- package/augment-extensions/coding-standards/html/examples/responsive-layout.html +505 -0
- package/augment-extensions/coding-standards/html/module.json +44 -0
- package/augment-extensions/coding-standards/html/rules/html-standards.md +349 -0
- package/augment-extensions/coding-standards/html-css-js/README.md +194 -0
- package/augment-extensions/coding-standards/html-css-js/examples/async-examples.js +487 -0
- package/augment-extensions/coding-standards/html-css-js/examples/css-examples.css +550 -0
- package/augment-extensions/coding-standards/html-css-js/examples/dom-examples.js +667 -0
- package/augment-extensions/coding-standards/html-css-js/examples/html-examples.html +267 -0
- package/augment-extensions/coding-standards/html-css-js/examples/javascript-examples.js +612 -0
- package/augment-extensions/coding-standards/html-css-js/examples/responsive-layout.html +505 -0
- package/augment-extensions/coding-standards/html-css-js/module.json +48 -0
- package/augment-extensions/coding-standards/html-css-js/rules/async-patterns.md +515 -0
- package/augment-extensions/coding-standards/html-css-js/rules/css-modern-features.md +448 -0
- package/augment-extensions/coding-standards/html-css-js/rules/css-standards.md +492 -0
- package/augment-extensions/coding-standards/html-css-js/rules/dom-manipulation.md +439 -0
- package/augment-extensions/coding-standards/html-css-js/rules/html-standards.md +349 -0
- package/augment-extensions/coding-standards/html-css-js/rules/javascript-standards.md +486 -0
- package/augment-extensions/coding-standards/html-css-js/rules/performance.md +463 -0
- package/augment-extensions/coding-standards/html-css-js/rules/tooling.md +543 -0
- package/augment-extensions/coding-standards/js/README.md +46 -0
- package/augment-extensions/coding-standards/js/examples/async-examples.js +487 -0
- package/augment-extensions/coding-standards/js/examples/dom-examples.js +667 -0
- package/augment-extensions/coding-standards/js/examples/javascript-examples.js +612 -0
- package/augment-extensions/coding-standards/js/module.json +49 -0
- package/augment-extensions/coding-standards/js/rules/async-patterns.md +515 -0
- package/augment-extensions/coding-standards/js/rules/dom-manipulation.md +439 -0
- package/augment-extensions/coding-standards/js/rules/javascript-standards.md +486 -0
- package/augment-extensions/coding-standards/js/rules/performance.md +463 -0
- package/augment-extensions/coding-standards/js/rules/tooling.md +543 -0
- package/augment-extensions/coding-standards/php/README.md +248 -0
- package/augment-extensions/coding-standards/php/examples/api-endpoint-example.php +204 -0
- package/augment-extensions/coding-standards/php/examples/cli-command-example.php +206 -0
- package/augment-extensions/coding-standards/php/examples/legacy-refactoring-example.php +234 -0
- package/augment-extensions/coding-standards/php/examples/web-application-example.php +211 -0
- package/augment-extensions/coding-standards/php/examples/woocommerce-extension-example.php +215 -0
- package/augment-extensions/coding-standards/php/examples/wordpress-plugin-example.php +189 -0
- package/augment-extensions/coding-standards/php/module.json +166 -0
- package/augment-extensions/coding-standards/php/rules/api-development.md +480 -0
- package/augment-extensions/coding-standards/php/rules/category-configuration.md +332 -0
- package/augment-extensions/coding-standards/php/rules/cli-tools.md +472 -0
- package/augment-extensions/coding-standards/php/rules/cms-integration.md +561 -0
- package/augment-extensions/coding-standards/php/rules/code-quality.md +402 -0
- package/augment-extensions/coding-standards/php/rules/documentation.md +425 -0
- package/augment-extensions/coding-standards/php/rules/ecommerce.md +627 -0
- package/augment-extensions/coding-standards/php/rules/error-handling.md +336 -0
- package/augment-extensions/coding-standards/php/rules/legacy-migration.md +677 -0
- package/augment-extensions/coding-standards/php/rules/naming-conventions.md +279 -0
- package/augment-extensions/coding-standards/php/rules/performance.md +392 -0
- package/augment-extensions/coding-standards/php/rules/psr-standards.md +186 -0
- package/augment-extensions/coding-standards/php/rules/security.md +358 -0
- package/augment-extensions/coding-standards/php/rules/testing.md +403 -0
- package/augment-extensions/coding-standards/php/rules/type-declarations.md +331 -0
- package/augment-extensions/coding-standards/php/rules/web-applications.md +426 -0
- package/augment-extensions/coding-standards/powershell/README.md +154 -0
- package/augment-extensions/coding-standards/powershell/examples/admin-example.ps1 +272 -0
- package/augment-extensions/coding-standards/powershell/examples/automation-example.ps1 +173 -0
- package/augment-extensions/coding-standards/powershell/examples/cloud-example.ps1 +243 -0
- package/augment-extensions/coding-standards/powershell/examples/cross-platform-example.ps1 +297 -0
- package/augment-extensions/coding-standards/powershell/examples/dsc-example.ps1 +224 -0
- package/augment-extensions/coding-standards/powershell/examples/legacy-migration-example.ps1 +340 -0
- package/augment-extensions/coding-standards/powershell/examples/module-example.psm1 +255 -0
- package/augment-extensions/coding-standards/powershell/module.json +165 -0
- package/augment-extensions/coding-standards/powershell/rules/administrative-tools.md +439 -0
- package/augment-extensions/coding-standards/powershell/rules/automation-scripts.md +240 -0
- package/augment-extensions/coding-standards/powershell/rules/cloud-orchestration.md +384 -0
- package/augment-extensions/coding-standards/powershell/rules/configuration-schema.md +383 -0
- package/augment-extensions/coding-standards/powershell/rules/cross-platform-scripts.md +482 -0
- package/augment-extensions/coding-standards/powershell/rules/dsc-configurations.md +296 -0
- package/augment-extensions/coding-standards/powershell/rules/error-handling.md +314 -0
- package/augment-extensions/coding-standards/powershell/rules/legacy-migrations.md +466 -0
- package/augment-extensions/coding-standards/powershell/rules/modules-functions.md +244 -0
- package/augment-extensions/coding-standards/powershell/rules/naming-conventions.md +266 -0
- package/augment-extensions/coding-standards/powershell/rules/performance-optimization.md +209 -0
- package/augment-extensions/coding-standards/powershell/rules/security-practices.md +314 -0
- package/augment-extensions/coding-standards/powershell/rules/testing-guidelines.md +268 -0
- package/augment-extensions/coding-standards/powershell/rules/universal-standards.md +197 -0
- package/augment-extensions/coding-standards/python/README.md +12 -8
- package/augment-extensions/coding-standards/python/examples/best-practices.py +373 -0
- package/augment-extensions/coding-standards/python/module.json +8 -4
- package/augment-extensions/coding-standards/python/rules/async-patterns.md +884 -0
- package/augment-extensions/coding-standards/python/rules/documentation.md +831 -0
- package/augment-extensions/coding-standards/python/rules/error-handling.md +855 -68
- package/augment-extensions/coding-standards/python/rules/testing.md +409 -0
- package/augment-extensions/coding-standards/python/rules/tooling.md +446 -0
- package/augment-extensions/coding-standards/python/rules/type-hints.md +115 -50
- package/augment-extensions/collections/html-css-js/README.md +82 -0
- package/augment-extensions/collections/html-css-js/collection.json +41 -0
- package/augment-extensions/domain-rules/database/README.md +161 -0
- package/augment-extensions/domain-rules/database/examples/flat-database-example.md +793 -0
- package/augment-extensions/domain-rules/database/examples/hybrid-database-example.md +1132 -0
- package/augment-extensions/domain-rules/database/examples/nosql-document-example.md +868 -0
- package/augment-extensions/domain-rules/database/examples/nosql-graph-example.md +805 -0
- package/augment-extensions/domain-rules/database/examples/relational-schema-example.md +621 -0
- package/augment-extensions/domain-rules/database/examples/vector-database-example.md +965 -0
- package/augment-extensions/domain-rules/database/module.json +28 -0
- package/augment-extensions/domain-rules/database/rules/flat-databases.md +624 -0
- package/augment-extensions/domain-rules/database/rules/nosql-databases.md +588 -0
- package/augment-extensions/domain-rules/database/rules/nosql-document-stores.md +856 -0
- package/augment-extensions/domain-rules/database/rules/nosql-graph-databases.md +778 -0
- package/augment-extensions/domain-rules/database/rules/nosql-key-value-stores.md +963 -0
- package/augment-extensions/domain-rules/database/rules/performance-optimization.md +1076 -0
- package/augment-extensions/domain-rules/database/rules/relational-databases.md +697 -0
- package/augment-extensions/domain-rules/database/rules/relational-indexing.md +671 -0
- package/augment-extensions/domain-rules/database/rules/relational-query-optimization.md +607 -0
- package/augment-extensions/domain-rules/database/rules/relational-schema-design.md +907 -0
- package/augment-extensions/domain-rules/database/rules/relational-transactions.md +783 -0
- package/augment-extensions/domain-rules/database/rules/security-standards.md +980 -0
- package/augment-extensions/domain-rules/database/rules/universal-best-practices.md +485 -0
- package/augment-extensions/domain-rules/database/rules/vector-databases.md +521 -0
- package/augment-extensions/domain-rules/database/rules/vector-embeddings.md +858 -0
- package/augment-extensions/domain-rules/database/rules/vector-indexing.md +934 -0
- package/augment-extensions/domain-rules/mcp/README.md +150 -0
- package/augment-extensions/domain-rules/mcp/examples/compressed-example.md +522 -0
- package/augment-extensions/domain-rules/mcp/examples/graph-augmented-example.md +520 -0
- package/augment-extensions/domain-rules/mcp/examples/hybrid-example.md +570 -0
- package/augment-extensions/domain-rules/mcp/examples/state-based-example.md +427 -0
- package/augment-extensions/domain-rules/mcp/examples/token-based-example.md +435 -0
- package/augment-extensions/domain-rules/mcp/examples/vector-based-example.md +502 -0
- package/augment-extensions/domain-rules/mcp/module.json +49 -0
- package/augment-extensions/domain-rules/mcp/rules/compressed-mcp.md +595 -0
- package/augment-extensions/domain-rules/mcp/rules/configuration.md +345 -0
- package/augment-extensions/domain-rules/mcp/rules/graph-augmented-mcp.md +687 -0
- package/augment-extensions/domain-rules/mcp/rules/hybrid-mcp.md +636 -0
- package/augment-extensions/domain-rules/mcp/rules/state-based-mcp.md +484 -0
- package/augment-extensions/domain-rules/mcp/rules/testing-validation.md +360 -0
- package/augment-extensions/domain-rules/mcp/rules/token-based-mcp.md +393 -0
- package/augment-extensions/domain-rules/mcp/rules/universal-rules.md +194 -0
- package/augment-extensions/domain-rules/mcp/rules/vector-based-mcp.md +625 -0
- package/augment-extensions/domain-rules/wordpress/README.md +163 -0
- package/augment-extensions/domain-rules/wordpress/module.json +32 -0
- package/augment-extensions/domain-rules/wordpress/rules/coding-standards.md +617 -0
- package/augment-extensions/domain-rules/wordpress/rules/directory-structure.md +270 -0
- package/augment-extensions/domain-rules/wordpress/rules/file-patterns.md +423 -0
- package/augment-extensions/domain-rules/wordpress/rules/gutenberg-blocks.md +493 -0
- package/augment-extensions/domain-rules/wordpress/rules/performance.md +568 -0
- package/augment-extensions/domain-rules/wordpress/rules/plugin-development.md +510 -0
- package/augment-extensions/domain-rules/wordpress/rules/project-detection.md +251 -0
- package/augment-extensions/domain-rules/wordpress/rules/rest-api.md +501 -0
- package/augment-extensions/domain-rules/wordpress/rules/security.md +564 -0
- package/augment-extensions/domain-rules/wordpress/rules/theme-development.md +388 -0
- package/augment-extensions/domain-rules/wordpress/rules/woocommerce.md +441 -0
- package/augment-extensions/domain-rules/wordpress-plugin/README.md +139 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/ajax-plugin.md +1599 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/custom-post-type-plugin.md +1727 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/gutenberg-block-plugin.md +428 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/gutenberg-block.md +422 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/mvc-plugin.md +1623 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/object-oriented-plugin.md +1343 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/rest-endpoint.md +734 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/settings-page-plugin.md +1350 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/simple-procedural-plugin.md +503 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/singleton-plugin.md +971 -0
- package/augment-extensions/domain-rules/wordpress-plugin/module.json +53 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/activation-hooks.md +770 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/admin-interface.md +874 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/ajax-handlers.md +629 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/asset-management.md +559 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/context-providers.md +709 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/cron-jobs.md +736 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/database-management.md +1057 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/documentation-standards.md +463 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/frontend-functionality.md +478 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/gutenberg-blocks.md +818 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/internationalization.md +416 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/migration.md +667 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/performance-optimization.md +878 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/plugin-architecture.md +693 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/plugin-structure.md +352 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/rest-api.md +818 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/scaffolding-workflow.md +624 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/security-best-practices.md +866 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/testing-patterns.md +1165 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/testing.md +414 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/vscode-integration.md +751 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/woocommerce-integration.md +949 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/wordpress-org-submission.md +458 -0
- package/augment-extensions/examples/gutenberg-block-plugin/README.md +101 -0
- package/augment-extensions/examples/gutenberg-block-plugin/examples/testimonial-block.md +428 -0
- package/augment-extensions/examples/gutenberg-block-plugin/module.json +40 -0
- package/augment-extensions/examples/rest-api-plugin/README.md +98 -0
- package/augment-extensions/examples/rest-api-plugin/examples/task-manager-api.md +1299 -0
- package/augment-extensions/examples/rest-api-plugin/module.json +40 -0
- package/augment-extensions/examples/woocommerce-extension/README.md +98 -0
- package/augment-extensions/examples/woocommerce-extension/examples/product-customizer.md +763 -0
- package/augment-extensions/examples/woocommerce-extension/module.json +40 -0
- package/augment-extensions/workflows/beads/module.json +4 -3
- package/augment-extensions/workflows/database/README.md +195 -0
- package/augment-extensions/workflows/database/ai-prompt-testing.md +295 -0
- package/augment-extensions/workflows/database/examples/migration-example.md +498 -0
- package/augment-extensions/workflows/database/examples/optimization-example.md +496 -0
- package/augment-extensions/workflows/database/examples/schema-design-example.md +444 -0
- package/augment-extensions/workflows/database/module.json +42 -0
- package/augment-extensions/workflows/database/rules/data-migration.md +249 -0
- package/augment-extensions/workflows/database/rules/documentation-standards.md +339 -0
- package/augment-extensions/workflows/database/rules/migration-workflow.md +352 -0
- package/augment-extensions/workflows/database/rules/optimization-workflow.md +435 -0
- package/augment-extensions/workflows/database/rules/schema-design-workflow.md +535 -0
- package/augment-extensions/workflows/database/rules/testing-patterns.md +305 -0
- package/augment-extensions/workflows/database/rules/workflow.md +458 -0
- package/augment-extensions/workflows/openspec/module.json +4 -3
- package/augment-extensions/workflows/wordpress-plugin/README.md +232 -0
- package/augment-extensions/workflows/wordpress-plugin/ai-prompts.md +839 -0
- package/augment-extensions/workflows/wordpress-plugin/bead-decomposition-patterns.md +854 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/complete-plugin-example.md +540 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/custom-post-type-example.md +1083 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/feature-addition-workflow.md +669 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/plugin-creation-workflow.md +597 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/secure-form-handler-example.md +925 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/security-audit-workflow.md +752 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/wordpress-org-submission-workflow.md +773 -0
- package/augment-extensions/workflows/wordpress-plugin/module.json +49 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/best-practices.md +942 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/development-workflow.md +702 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/submission-workflow.md +728 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/testing-workflow.md +775 -0
- package/augment-extensions/writing-standards/screenplay/README.md +171 -0
- package/augment-extensions/writing-standards/screenplay/examples/aaa-hollywood-scene.fountain +164 -0
- package/augment-extensions/writing-standards/screenplay/module.json +124 -0
- package/augment-extensions/writing-standards/screenplay/rules/universal-formatting.md +339 -0
- package/cli/MODULES.md +302 -0
- package/cli/dist/cli.js +142 -9
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/catalog.d.ts +13 -0
- package/cli/dist/commands/catalog.d.ts.map +1 -0
- package/cli/dist/commands/catalog.js +104 -0
- package/cli/dist/commands/catalog.js.map +1 -0
- package/cli/dist/commands/gui.d.ts +6 -0
- package/cli/dist/commands/gui.d.ts.map +1 -0
- package/cli/dist/commands/gui.js +211 -0
- package/cli/dist/commands/gui.js.map +1 -0
- package/cli/dist/commands/init.d.ts.map +1 -1
- package/cli/dist/commands/init.js +12 -0
- package/cli/dist/commands/init.js.map +1 -1
- package/cli/dist/commands/install-rules.d.ts +14 -0
- package/cli/dist/commands/install-rules.d.ts.map +1 -0
- package/cli/dist/commands/install-rules.js +127 -0
- package/cli/dist/commands/install-rules.js.map +1 -0
- package/cli/dist/commands/link.d.ts.map +1 -1
- package/cli/dist/commands/link.js +9 -11
- package/cli/dist/commands/link.js.map +1 -1
- package/cli/dist/commands/list.d.ts.map +1 -1
- package/cli/dist/commands/list.js +11 -28
- package/cli/dist/commands/list.js.map +1 -1
- package/cli/dist/commands/mcp.d.ts +48 -0
- package/cli/dist/commands/mcp.d.ts.map +1 -0
- package/cli/dist/commands/mcp.js +229 -0
- package/cli/dist/commands/mcp.js.map +1 -0
- package/cli/dist/commands/self-remove.d.ts +7 -0
- package/cli/dist/commands/self-remove.d.ts.map +1 -0
- package/cli/dist/commands/self-remove.js +179 -0
- package/cli/dist/commands/self-remove.js.map +1 -0
- package/cli/dist/commands/show.d.ts.map +1 -1
- package/cli/dist/commands/show.js +42 -71
- package/cli/dist/commands/show.js.map +1 -1
- package/cli/dist/commands/skill.d.ts +67 -0
- package/cli/dist/commands/skill.d.ts.map +1 -0
- package/cli/dist/commands/skill.js +513 -0
- package/cli/dist/commands/skill.js.map +1 -0
- package/cli/dist/commands/unlink.d.ts +6 -0
- package/cli/dist/commands/unlink.d.ts.map +1 -0
- package/cli/dist/commands/unlink.js +115 -0
- package/cli/dist/commands/unlink.js.map +1 -0
- package/cli/dist/commands/validate.d.ts +6 -0
- package/cli/dist/commands/validate.d.ts.map +1 -0
- package/cli/dist/commands/validate.js +159 -0
- package/cli/dist/commands/validate.js.map +1 -0
- package/cli/dist/utils/catalog-sync.d.ts +22 -0
- package/cli/dist/utils/catalog-sync.d.ts.map +1 -0
- package/cli/dist/utils/catalog-sync.js +157 -0
- package/cli/dist/utils/catalog-sync.js.map +1 -0
- package/cli/dist/utils/character-count.d.ts +56 -0
- package/cli/dist/utils/character-count.d.ts.map +1 -0
- package/cli/dist/utils/character-count.js +190 -0
- package/cli/dist/utils/character-count.js.map +1 -0
- package/cli/dist/utils/documentation-validator.d.ts +18 -0
- package/cli/dist/utils/documentation-validator.d.ts.map +1 -0
- package/cli/dist/utils/documentation-validator.js +233 -0
- package/cli/dist/utils/documentation-validator.js.map +1 -0
- package/cli/dist/utils/install-rules.d.ts +32 -0
- package/cli/dist/utils/install-rules.d.ts.map +1 -0
- package/cli/dist/utils/install-rules.js +375 -0
- package/cli/dist/utils/install-rules.js.map +1 -0
- package/cli/dist/utils/mcp-integration.d.ts +70 -0
- package/cli/dist/utils/mcp-integration.d.ts.map +1 -0
- package/cli/dist/utils/mcp-integration.js +292 -0
- package/cli/dist/utils/mcp-integration.js.map +1 -0
- package/cli/dist/utils/module-system.d.ts +153 -0
- package/cli/dist/utils/module-system.d.ts.map +1 -0
- package/cli/dist/utils/module-system.js +528 -0
- package/cli/dist/utils/module-system.js.map +1 -0
- package/cli/dist/utils/modules-catalog.d.ts +33 -0
- package/cli/dist/utils/modules-catalog.d.ts.map +1 -0
- package/cli/dist/utils/modules-catalog.js +163 -0
- package/cli/dist/utils/modules-catalog.js.map +1 -0
- package/cli/dist/utils/rule-install-hooks.d.ts +19 -0
- package/cli/dist/utils/rule-install-hooks.d.ts.map +1 -0
- package/cli/dist/utils/rule-install-hooks.js +224 -0
- package/cli/dist/utils/rule-install-hooks.js.map +1 -0
- package/cli/dist/utils/skill-system.d.ts +95 -0
- package/cli/dist/utils/skill-system.d.ts.map +1 -0
- package/cli/dist/utils/skill-system.js +313 -0
- package/cli/dist/utils/skill-system.js.map +1 -0
- package/modules.md +534 -70
- package/package.json +12 -3
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
# Relational Query Optimization
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document covers query optimization techniques for relational databases, including query execution plans, JOIN optimization, subquery strategies, N+1 query prevention, and database-specific optimizations.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Query Execution Plans
|
|
10
|
+
|
|
11
|
+
### Understanding Execution Plans
|
|
12
|
+
|
|
13
|
+
**Purpose**: Visualize how the database executes a query
|
|
14
|
+
|
|
15
|
+
**Key concepts:**
|
|
16
|
+
- **Scan types**: Sequential scan, index scan, index-only scan
|
|
17
|
+
- **Join methods**: Nested loop, hash join, merge join
|
|
18
|
+
- **Cost estimates**: Relative cost of operations
|
|
19
|
+
- **Row estimates**: Expected number of rows processed
|
|
20
|
+
|
|
21
|
+
### Analyzing Execution Plans
|
|
22
|
+
|
|
23
|
+
#### PostgreSQL
|
|
24
|
+
|
|
25
|
+
```sql
|
|
26
|
+
-- Basic execution plan
|
|
27
|
+
EXPLAIN
|
|
28
|
+
SELECT u.name, o.total
|
|
29
|
+
FROM users u
|
|
30
|
+
JOIN orders o ON o.user_id = u.id
|
|
31
|
+
WHERE u.created_at > '2024-01-01';
|
|
32
|
+
|
|
33
|
+
-- Execution plan with actual runtime statistics
|
|
34
|
+
EXPLAIN ANALYZE
|
|
35
|
+
SELECT u.name, o.total
|
|
36
|
+
FROM users u
|
|
37
|
+
JOIN orders o ON o.user_id = u.id
|
|
38
|
+
WHERE u.created_at > '2024-01-01';
|
|
39
|
+
|
|
40
|
+
-- Detailed execution plan with buffer usage
|
|
41
|
+
EXPLAIN (ANALYZE, BUFFERS)
|
|
42
|
+
SELECT u.name, o.total
|
|
43
|
+
FROM users u
|
|
44
|
+
JOIN orders o ON o.user_id = u.id
|
|
45
|
+
WHERE u.created_at > '2024-01-01';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Key metrics:**
|
|
49
|
+
- **Seq Scan**: Full table scan (slow for large tables)
|
|
50
|
+
- **Index Scan**: Using index to find rows (fast)
|
|
51
|
+
- **Index Only Scan**: Using covering index (fastest)
|
|
52
|
+
- **Bitmap Heap Scan**: Using index bitmap (good for multiple conditions)
|
|
53
|
+
|
|
54
|
+
#### MySQL
|
|
55
|
+
|
|
56
|
+
```sql
|
|
57
|
+
-- Execution plan
|
|
58
|
+
EXPLAIN
|
|
59
|
+
SELECT u.name, o.total
|
|
60
|
+
FROM users u
|
|
61
|
+
JOIN orders o ON o.user_id = u.id
|
|
62
|
+
WHERE u.created_at > '2024-01-01';
|
|
63
|
+
|
|
64
|
+
-- Extended execution plan
|
|
65
|
+
EXPLAIN FORMAT=JSON
|
|
66
|
+
SELECT u.name, o.total
|
|
67
|
+
FROM users u
|
|
68
|
+
JOIN orders o ON o.user_id = u.id
|
|
69
|
+
WHERE u.created_at > '2024-01-01';
|
|
70
|
+
|
|
71
|
+
-- Analyze query (executes and shows stats)
|
|
72
|
+
EXPLAIN ANALYZE
|
|
73
|
+
SELECT u.name, o.total
|
|
74
|
+
FROM users u
|
|
75
|
+
JOIN orders o ON o.user_id = u.id
|
|
76
|
+
WHERE u.created_at > '2024-01-01';
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### SQL Server
|
|
80
|
+
|
|
81
|
+
```sql
|
|
82
|
+
-- Show execution plan
|
|
83
|
+
SET SHOWPLAN_TEXT ON;
|
|
84
|
+
GO
|
|
85
|
+
SELECT u.name, o.total
|
|
86
|
+
FROM users u
|
|
87
|
+
JOIN orders o ON o.user_id = u.id
|
|
88
|
+
WHERE u.created_at > '2024-01-01';
|
|
89
|
+
GO
|
|
90
|
+
SET SHOWPLAN_TEXT OFF;
|
|
91
|
+
GO
|
|
92
|
+
|
|
93
|
+
-- Include actual execution plan
|
|
94
|
+
SET STATISTICS PROFILE ON;
|
|
95
|
+
GO
|
|
96
|
+
SELECT u.name, o.total
|
|
97
|
+
FROM users u
|
|
98
|
+
JOIN orders o ON o.user_id = u.id
|
|
99
|
+
WHERE u.created_at > '2024-01-01';
|
|
100
|
+
GO
|
|
101
|
+
SET STATISTICS PROFILE OFF;
|
|
102
|
+
GO
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## JOIN Optimization
|
|
108
|
+
|
|
109
|
+
### JOIN Types and Performance
|
|
110
|
+
|
|
111
|
+
#### INNER JOIN
|
|
112
|
+
|
|
113
|
+
```sql
|
|
114
|
+
-- ✅ GOOD: Use INNER JOIN for required relationships
|
|
115
|
+
SELECT u.name, o.total
|
|
116
|
+
FROM users u
|
|
117
|
+
INNER JOIN orders o ON o.user_id = u.id;
|
|
118
|
+
|
|
119
|
+
-- ❌ BAD: Implicit join (less readable)
|
|
120
|
+
SELECT u.name, o.total
|
|
121
|
+
FROM users u, orders o
|
|
122
|
+
WHERE o.user_id = u.id;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### LEFT JOIN
|
|
126
|
+
|
|
127
|
+
```sql
|
|
128
|
+
-- ✅ GOOD: Use LEFT JOIN when right side is optional
|
|
129
|
+
SELECT u.name, COUNT(o.id) AS order_count
|
|
130
|
+
FROM users u
|
|
131
|
+
LEFT JOIN orders o ON o.user_id = u.id
|
|
132
|
+
GROUP BY u.id, u.name;
|
|
133
|
+
|
|
134
|
+
-- ❌ BAD: Using LEFT JOIN when INNER JOIN would work
|
|
135
|
+
SELECT u.name, o.total
|
|
136
|
+
FROM users u
|
|
137
|
+
LEFT JOIN orders o ON o.user_id = u.id
|
|
138
|
+
WHERE o.id IS NOT NULL; -- This makes it an INNER JOIN
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### JOIN Order Optimization
|
|
142
|
+
|
|
143
|
+
**Principle**: Join smaller result sets first
|
|
144
|
+
|
|
145
|
+
```sql
|
|
146
|
+
-- ❌ BAD: Large table first
|
|
147
|
+
SELECT *
|
|
148
|
+
FROM orders o
|
|
149
|
+
JOIN users u ON u.id = o.user_id
|
|
150
|
+
WHERE u.email = 'user@example.com';
|
|
151
|
+
|
|
152
|
+
-- ✅ GOOD: Filter first, then join
|
|
153
|
+
SELECT *
|
|
154
|
+
FROM users u
|
|
155
|
+
JOIN orders o ON o.user_id = u.id
|
|
156
|
+
WHERE u.email = 'user@example.com';
|
|
157
|
+
|
|
158
|
+
-- ✅ BETTER: Use subquery to filter first
|
|
159
|
+
SELECT *
|
|
160
|
+
FROM (
|
|
161
|
+
SELECT id FROM users WHERE email = 'user@example.com'
|
|
162
|
+
) u
|
|
163
|
+
JOIN orders o ON o.user_id = u.id;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Multiple JOINs
|
|
167
|
+
|
|
168
|
+
```sql
|
|
169
|
+
-- ✅ GOOD: Join in logical order
|
|
170
|
+
SELECT u.name, o.total, p.name AS product_name
|
|
171
|
+
FROM users u
|
|
172
|
+
JOIN orders o ON o.user_id = u.id
|
|
173
|
+
JOIN order_items oi ON oi.order_id = o.id
|
|
174
|
+
JOIN products p ON p.id = oi.product_id
|
|
175
|
+
WHERE u.created_at > '2024-01-01';
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### JOIN Method Selection
|
|
179
|
+
|
|
180
|
+
**Database chooses based on:**
|
|
181
|
+
- Table sizes
|
|
182
|
+
- Available indexes
|
|
183
|
+
- Join conditions
|
|
184
|
+
- Statistics
|
|
185
|
+
|
|
186
|
+
**Common methods:**
|
|
187
|
+
- **Nested Loop**: Good for small datasets, indexed joins
|
|
188
|
+
- **Hash Join**: Good for large datasets, equality conditions
|
|
189
|
+
- **Merge Join**: Good for sorted data, range conditions
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Subquery vs JOIN
|
|
194
|
+
|
|
195
|
+
### When to Use Subqueries
|
|
196
|
+
|
|
197
|
+
```sql
|
|
198
|
+
-- ✅ GOOD: Subquery for existence check
|
|
199
|
+
SELECT *
|
|
200
|
+
FROM users u
|
|
201
|
+
WHERE EXISTS (
|
|
202
|
+
SELECT 1 FROM orders o WHERE o.user_id = u.id
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
-- ✅ GOOD: Subquery for scalar value
|
|
206
|
+
SELECT u.name,
|
|
207
|
+
(SELECT COUNT(*) FROM orders WHERE user_id = u.id) AS order_count
|
|
208
|
+
FROM users u;
|
|
209
|
+
|
|
210
|
+
-- ❌ BAD: Subquery in WHERE with IN (can be slow)
|
|
211
|
+
SELECT *
|
|
212
|
+
FROM users
|
|
213
|
+
WHERE id IN (SELECT user_id FROM orders);
|
|
214
|
+
|
|
215
|
+
-- ✅ BETTER: Use JOIN instead
|
|
216
|
+
SELECT DISTINCT u.*
|
|
217
|
+
FROM users u
|
|
218
|
+
JOIN orders o ON o.user_id = u.id;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Correlated vs Non-Correlated Subqueries
|
|
222
|
+
|
|
223
|
+
```sql
|
|
224
|
+
-- ❌ BAD: Correlated subquery (executes for each row)
|
|
225
|
+
SELECT u.name,
|
|
226
|
+
(SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) AS order_count
|
|
227
|
+
FROM users u;
|
|
228
|
+
|
|
229
|
+
-- ✅ BETTER: Use JOIN with GROUP BY
|
|
230
|
+
SELECT u.name, COUNT(o.id) AS order_count
|
|
231
|
+
FROM users u
|
|
232
|
+
LEFT JOIN orders o ON o.user_id = u.id
|
|
233
|
+
GROUP BY u.id, u.name;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Avoiding N+1 Queries
|
|
239
|
+
|
|
240
|
+
### The N+1 Problem
|
|
241
|
+
|
|
242
|
+
**Problem**: Executing 1 query to get N records, then N queries to get related data
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
// ❌ BAD: N+1 queries
|
|
246
|
+
const users = await db.query('SELECT * FROM users');
|
|
247
|
+
for (const user of users) {
|
|
248
|
+
const orders = await db.query('SELECT * FROM orders WHERE user_id = ?', [user.id]);
|
|
249
|
+
user.orders = orders;
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Solutions
|
|
254
|
+
|
|
255
|
+
#### 1. Use JOINs
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
// ✅ GOOD: Single query with JOIN
|
|
259
|
+
const result = await db.query(`
|
|
260
|
+
SELECT u.*, o.id AS order_id, o.total, o.created_at AS order_date
|
|
261
|
+
FROM users u
|
|
262
|
+
LEFT JOIN orders o ON o.user_id = u.id
|
|
263
|
+
`);
|
|
264
|
+
|
|
265
|
+
// Group results by user
|
|
266
|
+
const users = groupByUser(result);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### 2. Use Batch Loading
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
// ✅ GOOD: Batch load related data
|
|
273
|
+
const users = await db.query('SELECT * FROM users');
|
|
274
|
+
const userIds = users.map(u => u.id);
|
|
275
|
+
|
|
276
|
+
const orders = await db.query(
|
|
277
|
+
'SELECT * FROM orders WHERE user_id = ANY(?)',
|
|
278
|
+
[userIds]
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
// Map orders to users
|
|
282
|
+
const ordersByUser = groupBy(orders, 'user_id');
|
|
283
|
+
users.forEach(user => {
|
|
284
|
+
user.orders = ordersByUser[user.id] || [];
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
#### 3. Use DataLoader (GraphQL)
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
// ✅ GOOD: Use DataLoader for batching
|
|
292
|
+
const orderLoader = new DataLoader(async (userIds) => {
|
|
293
|
+
const orders = await db.query(
|
|
294
|
+
'SELECT * FROM orders WHERE user_id = ANY(?)',
|
|
295
|
+
[userIds]
|
|
296
|
+
);
|
|
297
|
+
return userIds.map(id => orders.filter(o => o.user_id === id));
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Usage
|
|
301
|
+
const orders = await orderLoader.load(userId);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## SELECT Optimization
|
|
307
|
+
|
|
308
|
+
### Select Only Needed Columns
|
|
309
|
+
|
|
310
|
+
```sql
|
|
311
|
+
-- ❌ BAD: Select all columns
|
|
312
|
+
SELECT * FROM users;
|
|
313
|
+
|
|
314
|
+
-- ✅ GOOD: Select only needed columns
|
|
315
|
+
SELECT id, email, name FROM users;
|
|
316
|
+
|
|
317
|
+
-- ✅ BETTER: Use covering index
|
|
318
|
+
CREATE INDEX idx_users_email_name ON users(email, name);
|
|
319
|
+
SELECT email, name FROM users WHERE email = 'user@example.com';
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Avoid SELECT DISTINCT When Possible
|
|
323
|
+
|
|
324
|
+
```sql
|
|
325
|
+
-- ❌ BAD: DISTINCT to hide duplicate rows
|
|
326
|
+
SELECT DISTINCT u.name
|
|
327
|
+
FROM users u
|
|
328
|
+
JOIN orders o ON o.user_id = u.id;
|
|
329
|
+
|
|
330
|
+
-- ✅ BETTER: Use GROUP BY
|
|
331
|
+
SELECT u.name
|
|
332
|
+
FROM users u
|
|
333
|
+
JOIN orders o ON o.user_id = u.id
|
|
334
|
+
GROUP BY u.id, u.name;
|
|
335
|
+
|
|
336
|
+
-- ✅ BEST: Use EXISTS if you only need to check existence
|
|
337
|
+
SELECT u.name
|
|
338
|
+
FROM users u
|
|
339
|
+
WHERE EXISTS (SELECT 1 FROM orders WHERE user_id = u.id);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## WHERE Clause Optimization
|
|
345
|
+
|
|
346
|
+
### Use Indexes Effectively
|
|
347
|
+
|
|
348
|
+
```sql
|
|
349
|
+
-- ✅ GOOD: Indexed column in WHERE
|
|
350
|
+
SELECT * FROM users WHERE email = 'user@example.com';
|
|
351
|
+
|
|
352
|
+
-- ❌ BAD: Function on indexed column (can't use index)
|
|
353
|
+
SELECT * FROM users WHERE LOWER(email) = 'user@example.com';
|
|
354
|
+
|
|
355
|
+
-- ✅ BETTER: Use functional index
|
|
356
|
+
CREATE INDEX idx_users_email_lower ON users(LOWER(email));
|
|
357
|
+
SELECT * FROM users WHERE LOWER(email) = 'user@example.com';
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Avoid OR Conditions
|
|
361
|
+
|
|
362
|
+
```sql
|
|
363
|
+
-- ❌ BAD: OR condition (may not use indexes efficiently)
|
|
364
|
+
SELECT * FROM users WHERE email = 'user@example.com' OR name = 'John';
|
|
365
|
+
|
|
366
|
+
-- ✅ BETTER: Use UNION
|
|
367
|
+
SELECT * FROM users WHERE email = 'user@example.com'
|
|
368
|
+
UNION
|
|
369
|
+
SELECT * FROM users WHERE name = 'John';
|
|
370
|
+
|
|
371
|
+
-- ✅ BEST: Use IN for same column
|
|
372
|
+
SELECT * FROM users WHERE status IN ('active', 'pending');
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Use BETWEEN for Ranges
|
|
376
|
+
|
|
377
|
+
```sql
|
|
378
|
+
-- ❌ BAD: Multiple comparisons
|
|
379
|
+
SELECT * FROM orders WHERE created_at >= '2024-01-01' AND created_at <= '2024-12-31';
|
|
380
|
+
|
|
381
|
+
-- ✅ GOOD: Use BETWEEN
|
|
382
|
+
SELECT * FROM orders WHERE created_at BETWEEN '2024-01-01' AND '2024-12-31';
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Aggregation Optimization
|
|
388
|
+
|
|
389
|
+
### Use Indexes for GROUP BY
|
|
390
|
+
|
|
391
|
+
```sql
|
|
392
|
+
-- ✅ GOOD: Index on GROUP BY column
|
|
393
|
+
CREATE INDEX idx_orders_user_id ON orders(user_id);
|
|
394
|
+
|
|
395
|
+
SELECT user_id, COUNT(*) AS order_count
|
|
396
|
+
FROM orders
|
|
397
|
+
GROUP BY user_id;
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Avoid HAVING When Possible
|
|
401
|
+
|
|
402
|
+
```sql
|
|
403
|
+
-- ❌ BAD: HAVING filters after aggregation
|
|
404
|
+
SELECT user_id, COUNT(*) AS order_count
|
|
405
|
+
FROM orders
|
|
406
|
+
GROUP BY user_id
|
|
407
|
+
HAVING user_id > 100;
|
|
408
|
+
|
|
409
|
+
-- ✅ BETTER: WHERE filters before aggregation
|
|
410
|
+
SELECT user_id, COUNT(*) AS order_count
|
|
411
|
+
FROM orders
|
|
412
|
+
WHERE user_id > 100
|
|
413
|
+
GROUP BY user_id;
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Use Materialized Views for Complex Aggregations
|
|
417
|
+
|
|
418
|
+
```sql
|
|
419
|
+
-- ✅ GOOD: Precompute expensive aggregations
|
|
420
|
+
CREATE MATERIALIZED VIEW user_order_stats AS
|
|
421
|
+
SELECT
|
|
422
|
+
u.id,
|
|
423
|
+
u.name,
|
|
424
|
+
COUNT(o.id) AS order_count,
|
|
425
|
+
SUM(o.total) AS total_spent,
|
|
426
|
+
MAX(o.created_at) AS last_order_date
|
|
427
|
+
FROM users u
|
|
428
|
+
LEFT JOIN orders o ON o.user_id = u.id
|
|
429
|
+
GROUP BY u.id, u.name;
|
|
430
|
+
|
|
431
|
+
-- Refresh periodically
|
|
432
|
+
REFRESH MATERIALIZED VIEW user_order_stats;
|
|
433
|
+
|
|
434
|
+
-- Query is now fast
|
|
435
|
+
SELECT * FROM user_order_stats WHERE order_count > 10;
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## Pagination Strategies
|
|
441
|
+
|
|
442
|
+
### Offset-Based Pagination
|
|
443
|
+
|
|
444
|
+
```sql
|
|
445
|
+
-- ❌ BAD: Large offset (slow for deep pages)
|
|
446
|
+
SELECT * FROM orders
|
|
447
|
+
ORDER BY created_at DESC
|
|
448
|
+
LIMIT 20 OFFSET 10000;
|
|
449
|
+
|
|
450
|
+
-- ✅ BETTER: Use indexed column for ordering
|
|
451
|
+
CREATE INDEX idx_orders_created_at ON orders(created_at DESC);
|
|
452
|
+
SELECT * FROM orders
|
|
453
|
+
ORDER BY created_at DESC
|
|
454
|
+
LIMIT 20 OFFSET 100;
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Cursor-Based Pagination
|
|
458
|
+
|
|
459
|
+
```sql
|
|
460
|
+
-- ✅ BEST: Use cursor (keyset pagination)
|
|
461
|
+
-- First page
|
|
462
|
+
SELECT * FROM orders
|
|
463
|
+
WHERE created_at < NOW()
|
|
464
|
+
ORDER BY created_at DESC
|
|
465
|
+
LIMIT 20;
|
|
466
|
+
|
|
467
|
+
-- Next page (using last created_at from previous page)
|
|
468
|
+
SELECT * FROM orders
|
|
469
|
+
WHERE created_at < '2024-01-15 10:30:00'
|
|
470
|
+
ORDER BY created_at DESC
|
|
471
|
+
LIMIT 20;
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**Benefits:**
|
|
475
|
+
- ✅ Consistent performance regardless of page depth
|
|
476
|
+
- ✅ No duplicate or missing rows when data changes
|
|
477
|
+
- ✅ Works well with real-time data
|
|
478
|
+
|
|
479
|
+
### Seek Method (Best for Large Datasets)
|
|
480
|
+
|
|
481
|
+
```sql
|
|
482
|
+
-- ✅ BEST: Seek method with composite key
|
|
483
|
+
CREATE INDEX idx_orders_created_id ON orders(created_at DESC, id DESC);
|
|
484
|
+
|
|
485
|
+
-- First page
|
|
486
|
+
SELECT * FROM orders
|
|
487
|
+
ORDER BY created_at DESC, id DESC
|
|
488
|
+
LIMIT 20;
|
|
489
|
+
|
|
490
|
+
-- Next page (using last created_at and id from previous page)
|
|
491
|
+
SELECT * FROM orders
|
|
492
|
+
WHERE (created_at, id) < ('2024-01-15 10:30:00', 12345)
|
|
493
|
+
ORDER BY created_at DESC, id DESC
|
|
494
|
+
LIMIT 20;
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## Database-Specific Optimizations
|
|
500
|
+
|
|
501
|
+
### PostgreSQL
|
|
502
|
+
|
|
503
|
+
```sql
|
|
504
|
+
-- Use EXPLAIN ANALYZE to identify slow queries
|
|
505
|
+
EXPLAIN (ANALYZE, BUFFERS)
|
|
506
|
+
SELECT * FROM orders WHERE user_id = 123;
|
|
507
|
+
|
|
508
|
+
-- Use partial indexes for filtered queries
|
|
509
|
+
CREATE INDEX idx_active_users ON users(email) WHERE status = 'active';
|
|
510
|
+
|
|
511
|
+
-- Use VACUUM ANALYZE to update statistics
|
|
512
|
+
VACUUM ANALYZE orders;
|
|
513
|
+
|
|
514
|
+
-- Use parallel query execution
|
|
515
|
+
SET max_parallel_workers_per_gather = 4;
|
|
516
|
+
|
|
517
|
+
-- Use LATERAL joins for correlated subqueries
|
|
518
|
+
SELECT u.*, recent_orders.*
|
|
519
|
+
FROM users u
|
|
520
|
+
LEFT JOIN LATERAL (
|
|
521
|
+
SELECT * FROM orders WHERE user_id = u.id ORDER BY created_at DESC LIMIT 5
|
|
522
|
+
) recent_orders ON true;
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### MySQL
|
|
526
|
+
|
|
527
|
+
```sql
|
|
528
|
+
-- Use EXPLAIN to analyze queries
|
|
529
|
+
EXPLAIN SELECT * FROM orders WHERE user_id = 123;
|
|
530
|
+
|
|
531
|
+
-- Use FORCE INDEX to force index usage
|
|
532
|
+
SELECT * FROM orders FORCE INDEX (idx_user_id) WHERE user_id = 123;
|
|
533
|
+
|
|
534
|
+
-- Use query cache (MySQL 5.7 and earlier)
|
|
535
|
+
SET GLOBAL query_cache_size = 268435456; -- 256MB
|
|
536
|
+
|
|
537
|
+
-- Optimize table to reclaim space
|
|
538
|
+
OPTIMIZE TABLE orders;
|
|
539
|
+
|
|
540
|
+
-- Analyze table to update statistics
|
|
541
|
+
ANALYZE TABLE orders;
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
### SQL Server
|
|
545
|
+
|
|
546
|
+
```sql
|
|
547
|
+
-- Use execution plan
|
|
548
|
+
SET SHOWPLAN_TEXT ON;
|
|
549
|
+
|
|
550
|
+
-- Use query hints
|
|
551
|
+
SELECT * FROM orders WITH (INDEX(idx_user_id)) WHERE user_id = 123;
|
|
552
|
+
|
|
553
|
+
-- Update statistics
|
|
554
|
+
UPDATE STATISTICS orders;
|
|
555
|
+
|
|
556
|
+
-- Rebuild indexes
|
|
557
|
+
ALTER INDEX idx_user_id ON orders REBUILD;
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
## Query Optimization Checklist
|
|
563
|
+
|
|
564
|
+
### Before Writing Queries
|
|
565
|
+
|
|
566
|
+
- [ ] Understand the data model and relationships
|
|
567
|
+
- [ ] Identify required columns (avoid SELECT *)
|
|
568
|
+
- [ ] Check existing indexes
|
|
569
|
+
- [ ] Consider query frequency and data volume
|
|
570
|
+
|
|
571
|
+
### While Writing Queries
|
|
572
|
+
|
|
573
|
+
- [ ] Use appropriate JOIN types
|
|
574
|
+
- [ ] Filter early (WHERE before JOIN when possible)
|
|
575
|
+
- [ ] Use indexes effectively
|
|
576
|
+
- [ ] Avoid functions on indexed columns
|
|
577
|
+
- [ ] Use prepared statements for security and performance
|
|
578
|
+
|
|
579
|
+
### After Writing Queries
|
|
580
|
+
|
|
581
|
+
- [ ] Analyze execution plan
|
|
582
|
+
- [ ] Check for table scans on large tables
|
|
583
|
+
- [ ] Verify indexes are being used
|
|
584
|
+
- [ ] Test with production-like data volumes
|
|
585
|
+
- [ ] Monitor query performance in production
|
|
586
|
+
|
|
587
|
+
### Optimization Techniques
|
|
588
|
+
|
|
589
|
+
- [ ] Add indexes on frequently queried columns
|
|
590
|
+
- [ ] Use covering indexes for index-only scans
|
|
591
|
+
- [ ] Rewrite subqueries as JOINs when appropriate
|
|
592
|
+
- [ ] Use batch loading to avoid N+1 queries
|
|
593
|
+
- [ ] Implement cursor-based pagination for large datasets
|
|
594
|
+
- [ ] Cache frequently accessed data
|
|
595
|
+
- [ ] Use materialized views for complex aggregations
|
|
596
|
+
|
|
597
|
+
---
|
|
598
|
+
|
|
599
|
+
## Related Documentation
|
|
600
|
+
|
|
601
|
+
- **relational-databases.md**: Relational database fundamentals
|
|
602
|
+
- **relational-indexing.md**: Indexing strategies
|
|
603
|
+
- **relational-schema-design.md**: Schema design and normalization
|
|
604
|
+
- **performance-optimization.md**: General performance optimization
|
|
605
|
+
- **relational-transactions.md**: Transaction management
|
|
606
|
+
|
|
607
|
+
|