jorgex-stack 1.0.1 → 1.0.3

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.
Files changed (99) hide show
  1. package/PRD.md +310 -297
  2. package/README.md +68 -56
  3. package/dist/cli.js +37 -3
  4. package/package.json +1 -1
  5. package/stack/agents/code-simplifier.md +21 -10
  6. package/stack/agents/implementer.md +1 -0
  7. package/stack/agents/orchestrator.md +194 -192
  8. package/stack/agents/security-auditor.md +7 -0
  9. package/stack/agents/silent-failure-hunter.md +7 -0
  10. package/stack/agents/test-analyzer.md +7 -0
  11. package/stack/agents/tester.md +71 -71
  12. package/stack/agents/type-design-analyzer.md +1 -1
  13. package/stack/commands/lean-audit.md +59 -0
  14. package/stack/commands/xreview.md +82 -80
  15. package/stack/hooks/hooks.json +18 -18
  16. package/stack/scripts/post-pr-review.cjs +159 -156
  17. package/stack/skills/diagnose/SKILL.md +117 -117
  18. package/stack/skills/diagnose/scripts/hitl-loop.template.sh +41 -41
  19. package/stack/skills/find-skills/SKILL.md +133 -133
  20. package/stack/skills/lean-code/SKILL.md +69 -0
  21. package/stack/skills/mcp-builder/LICENSE.txt +201 -201
  22. package/stack/skills/mcp-builder/SKILL.md +236 -236
  23. package/stack/skills/mcp-builder/reference/evaluation.md +601 -601
  24. package/stack/skills/mcp-builder/reference/mcp_best_practices.md +249 -249
  25. package/stack/skills/mcp-builder/reference/node_mcp_server.md +969 -969
  26. package/stack/skills/mcp-builder/reference/python_mcp_server.md +718 -718
  27. package/stack/skills/mcp-builder/scripts/connections.py +151 -151
  28. package/stack/skills/mcp-builder/scripts/evaluation.py +373 -373
  29. package/stack/skills/mcp-builder/scripts/example_evaluation.xml +22 -22
  30. package/stack/skills/mcp-builder/scripts/requirements.txt +2 -2
  31. package/stack/skills/obsidian-cli/SKILL.md +106 -106
  32. package/stack/skills/obsidian-markdown/SKILL.md +196 -196
  33. package/stack/skills/obsidian-markdown/references/CALLOUTS.md +58 -58
  34. package/stack/skills/obsidian-markdown/references/EMBEDS.md +63 -63
  35. package/stack/skills/obsidian-markdown/references/PROPERTIES.md +61 -61
  36. package/stack/skills/react-doctor/SKILL.md +19 -19
  37. package/stack/skills/skill-creator/LICENSE.txt +201 -201
  38. package/stack/skills/skill-creator/agents/analyzer.md +274 -274
  39. package/stack/skills/skill-creator/agents/comparator.md +202 -202
  40. package/stack/skills/skill-creator/agents/grader.md +223 -223
  41. package/stack/skills/skill-creator/assets/eval_review.html +146 -146
  42. package/stack/skills/skill-creator/eval-viewer/generate_review.py +471 -471
  43. package/stack/skills/skill-creator/eval-viewer/viewer.html +1325 -1325
  44. package/stack/skills/skill-creator/references/schemas.md +430 -430
  45. package/stack/skills/skill-creator/scripts/aggregate_benchmark.py +401 -401
  46. package/stack/skills/skill-creator/scripts/generate_report.py +326 -326
  47. package/stack/skills/skill-creator/scripts/improve_description.py +248 -248
  48. package/stack/skills/skill-creator/scripts/package_skill.py +136 -136
  49. package/stack/skills/skill-creator/scripts/quick_validate.py +102 -102
  50. package/stack/skills/skill-creator/scripts/run_eval.py +310 -310
  51. package/stack/skills/skill-creator/scripts/run_loop.py +332 -332
  52. package/stack/skills/skill-creator/scripts/utils.py +47 -47
  53. package/stack/skills/supabase/SKILL.md +135 -135
  54. package/stack/skills/supabase/assets/feedback-issue-template.md +17 -17
  55. package/stack/skills/supabase/references/skill-feedback.md +17 -17
  56. package/stack/skills/supabase-postgres-best-practices/SKILL.md +64 -64
  57. package/stack/skills/supabase-postgres-best-practices/references/_contributing.md +170 -170
  58. package/stack/skills/supabase-postgres-best-practices/references/_sections.md +39 -39
  59. package/stack/skills/supabase-postgres-best-practices/references/_template.md +34 -34
  60. package/stack/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -55
  61. package/stack/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -49
  62. package/stack/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -46
  63. package/stack/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -44
  64. package/stack/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -41
  65. package/stack/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -46
  66. package/stack/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -54
  67. package/stack/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -53
  68. package/stack/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -50
  69. package/stack/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -50
  70. package/stack/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -56
  71. package/stack/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -68
  72. package/stack/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -50
  73. package/stack/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -54
  74. package/stack/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -45
  75. package/stack/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -55
  76. package/stack/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -55
  77. package/stack/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -44
  78. package/stack/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -40
  79. package/stack/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -48
  80. package/stack/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -43
  81. package/stack/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -45
  82. package/stack/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -80
  83. package/stack/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -46
  84. package/stack/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -59
  85. package/stack/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -55
  86. package/stack/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -55
  87. package/stack/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -61
  88. package/stack/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -54
  89. package/stack/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -50
  90. package/stack/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -63
  91. package/stack/skills/tdd/SKILL.md +109 -109
  92. package/stack/skills/tdd/deep-modules.md +33 -33
  93. package/stack/skills/tdd/interface-design.md +31 -31
  94. package/stack/skills/tdd/mocking.md +59 -59
  95. package/stack/skills/tdd/refactoring.md +10 -10
  96. package/stack/skills/tdd/tests.md +61 -61
  97. package/stack/skills/to-issues/SKILL.md +83 -83
  98. package/stack/skills/to-prd/SKILL.md +72 -72
  99. package/upstreams.json +96 -96
@@ -1,45 +1,45 @@
1
- ---
2
- title: Use EXPLAIN ANALYZE to Diagnose Slow Queries
3
- impact: LOW-MEDIUM
4
- impactDescription: Identify exact bottlenecks in query execution
5
- tags: explain, analyze, diagnostics, query-plan
6
- ---
7
-
8
- ## Use EXPLAIN ANALYZE to Diagnose Slow Queries
9
-
10
- EXPLAIN ANALYZE executes the query and shows actual timings, revealing the true performance bottlenecks.
11
-
12
- **Incorrect (guessing at performance issues):**
13
-
14
- ```sql
15
- -- Query is slow, but why?
16
- select * from orders where customer_id = 123 and status = 'pending';
17
- -- "It must be missing an index" - but which one?
18
- ```
19
-
20
- **Correct (use EXPLAIN ANALYZE):**
21
-
22
- ```sql
23
- explain (analyze, buffers, format text)
24
- select * from orders where customer_id = 123 and status = 'pending';
25
-
26
- -- Output reveals the issue:
27
- -- Seq Scan on orders (cost=0.00..25000.00 rows=50 width=100) (actual time=0.015..450.123 rows=50 loops=1)
28
- -- Filter: ((customer_id = 123) AND (status = 'pending'::text))
29
- -- Rows Removed by Filter: 999950
30
- -- Buffers: shared hit=5000 read=15000
31
- -- Planning Time: 0.150 ms
32
- -- Execution Time: 450.500 ms
33
- ```
34
-
35
- Key things to look for:
36
-
37
- ```sql
38
- -- Seq Scan on large tables = missing index
39
- -- Rows Removed by Filter = poor selectivity or missing index
40
- -- Buffers: read >> hit = data not cached, needs more memory
41
- -- Nested Loop with high loops = consider different join strategy
42
- -- Sort Method: external merge = work_mem too low
43
- ```
44
-
45
- Reference: [EXPLAIN](https://supabase.com/docs/guides/database/inspect)
1
+ ---
2
+ title: Use EXPLAIN ANALYZE to Diagnose Slow Queries
3
+ impact: LOW-MEDIUM
4
+ impactDescription: Identify exact bottlenecks in query execution
5
+ tags: explain, analyze, diagnostics, query-plan
6
+ ---
7
+
8
+ ## Use EXPLAIN ANALYZE to Diagnose Slow Queries
9
+
10
+ EXPLAIN ANALYZE executes the query and shows actual timings, revealing the true performance bottlenecks.
11
+
12
+ **Incorrect (guessing at performance issues):**
13
+
14
+ ```sql
15
+ -- Query is slow, but why?
16
+ select * from orders where customer_id = 123 and status = 'pending';
17
+ -- "It must be missing an index" - but which one?
18
+ ```
19
+
20
+ **Correct (use EXPLAIN ANALYZE):**
21
+
22
+ ```sql
23
+ explain (analyze, buffers, format text)
24
+ select * from orders where customer_id = 123 and status = 'pending';
25
+
26
+ -- Output reveals the issue:
27
+ -- Seq Scan on orders (cost=0.00..25000.00 rows=50 width=100) (actual time=0.015..450.123 rows=50 loops=1)
28
+ -- Filter: ((customer_id = 123) AND (status = 'pending'::text))
29
+ -- Rows Removed by Filter: 999950
30
+ -- Buffers: shared hit=5000 read=15000
31
+ -- Planning Time: 0.150 ms
32
+ -- Execution Time: 450.500 ms
33
+ ```
34
+
35
+ Key things to look for:
36
+
37
+ ```sql
38
+ -- Seq Scan on large tables = missing index
39
+ -- Rows Removed by Filter = poor selectivity or missing index
40
+ -- Buffers: read >> hit = data not cached, needs more memory
41
+ -- Nested Loop with high loops = consider different join strategy
42
+ -- Sort Method: external merge = work_mem too low
43
+ ```
44
+
45
+ Reference: [EXPLAIN](https://supabase.com/docs/guides/database/inspect)
@@ -1,55 +1,55 @@
1
- ---
2
- title: Enable pg_stat_statements for Query Analysis
3
- impact: LOW-MEDIUM
4
- impactDescription: Identify top resource-consuming queries
5
- tags: pg-stat-statements, monitoring, statistics, performance
6
- ---
7
-
8
- ## Enable pg_stat_statements for Query Analysis
9
-
10
- pg_stat_statements tracks execution statistics for all queries, helping identify slow and frequent queries.
11
-
12
- **Incorrect (no visibility into query patterns):**
13
-
14
- ```sql
15
- -- Database is slow, but which queries are the problem?
16
- -- No way to know without pg_stat_statements
17
- ```
18
-
19
- **Correct (enable and query pg_stat_statements):**
20
-
21
- ```sql
22
- -- Enable the extension
23
- create extension if not exists pg_stat_statements;
24
-
25
- -- Find slowest queries by total time
26
- select
27
- calls,
28
- round(total_exec_time::numeric, 2) as total_time_ms,
29
- round(mean_exec_time::numeric, 2) as mean_time_ms,
30
- query
31
- from pg_stat_statements
32
- order by total_exec_time desc
33
- limit 10;
34
-
35
- -- Find most frequent queries
36
- select calls, query
37
- from pg_stat_statements
38
- order by calls desc
39
- limit 10;
40
-
41
- -- Reset statistics after optimization
42
- select pg_stat_statements_reset();
43
- ```
44
-
45
- Key metrics to monitor:
46
-
47
- ```sql
48
- -- Queries with high mean time (candidates for optimization)
49
- select query, mean_exec_time, calls
50
- from pg_stat_statements
51
- where mean_exec_time > 100 -- > 100ms average
52
- order by mean_exec_time desc;
53
- ```
54
-
55
- Reference: [pg_stat_statements](https://supabase.com/docs/guides/database/extensions/pg_stat_statements)
1
+ ---
2
+ title: Enable pg_stat_statements for Query Analysis
3
+ impact: LOW-MEDIUM
4
+ impactDescription: Identify top resource-consuming queries
5
+ tags: pg-stat-statements, monitoring, statistics, performance
6
+ ---
7
+
8
+ ## Enable pg_stat_statements for Query Analysis
9
+
10
+ pg_stat_statements tracks execution statistics for all queries, helping identify slow and frequent queries.
11
+
12
+ **Incorrect (no visibility into query patterns):**
13
+
14
+ ```sql
15
+ -- Database is slow, but which queries are the problem?
16
+ -- No way to know without pg_stat_statements
17
+ ```
18
+
19
+ **Correct (enable and query pg_stat_statements):**
20
+
21
+ ```sql
22
+ -- Enable the extension
23
+ create extension if not exists pg_stat_statements;
24
+
25
+ -- Find slowest queries by total time
26
+ select
27
+ calls,
28
+ round(total_exec_time::numeric, 2) as total_time_ms,
29
+ round(mean_exec_time::numeric, 2) as mean_time_ms,
30
+ query
31
+ from pg_stat_statements
32
+ order by total_exec_time desc
33
+ limit 10;
34
+
35
+ -- Find most frequent queries
36
+ select calls, query
37
+ from pg_stat_statements
38
+ order by calls desc
39
+ limit 10;
40
+
41
+ -- Reset statistics after optimization
42
+ select pg_stat_statements_reset();
43
+ ```
44
+
45
+ Key metrics to monitor:
46
+
47
+ ```sql
48
+ -- Queries with high mean time (candidates for optimization)
49
+ select query, mean_exec_time, calls
50
+ from pg_stat_statements
51
+ where mean_exec_time > 100 -- > 100ms average
52
+ order by mean_exec_time desc;
53
+ ```
54
+
55
+ Reference: [pg_stat_statements](https://supabase.com/docs/guides/database/extensions/pg_stat_statements)
@@ -1,55 +1,55 @@
1
- ---
2
- title: Maintain Table Statistics with VACUUM and ANALYZE
3
- impact: MEDIUM
4
- impactDescription: 2-10x better query plans with accurate statistics
5
- tags: vacuum, analyze, statistics, maintenance, autovacuum
6
- ---
7
-
8
- ## Maintain Table Statistics with VACUUM and ANALYZE
9
-
10
- Outdated statistics cause the query planner to make poor decisions. VACUUM reclaims space, ANALYZE updates statistics.
11
-
12
- **Incorrect (stale statistics):**
13
-
14
- ```sql
15
- -- Table has 1M rows but stats say 1000
16
- -- Query planner chooses wrong strategy
17
- explain select * from orders where status = 'pending';
18
- -- Shows: Seq Scan (because stats show small table)
19
- -- Actually: Index Scan would be much faster
20
- ```
21
-
22
- **Correct (maintain fresh statistics):**
23
-
24
- ```sql
25
- -- Manually analyze after large data changes
26
- analyze orders;
27
-
28
- -- Analyze specific columns used in WHERE clauses
29
- analyze orders (status, created_at);
30
-
31
- -- Check when tables were last analyzed
32
- select
33
- relname,
34
- last_vacuum,
35
- last_autovacuum,
36
- last_analyze,
37
- last_autoanalyze
38
- from pg_stat_user_tables
39
- order by last_analyze nulls first;
40
- ```
41
-
42
- Autovacuum tuning for busy tables:
43
-
44
- ```sql
45
- -- Increase frequency for high-churn tables
46
- alter table orders set (
47
- autovacuum_vacuum_scale_factor = 0.05, -- Vacuum at 5% dead tuples (default 20%)
48
- autovacuum_analyze_scale_factor = 0.02 -- Analyze at 2% changes (default 10%)
49
- );
50
-
51
- -- Check autovacuum status
52
- select * from pg_stat_progress_vacuum;
53
- ```
54
-
55
- Reference: [VACUUM](https://supabase.com/docs/guides/database/database-size#vacuum-operations)
1
+ ---
2
+ title: Maintain Table Statistics with VACUUM and ANALYZE
3
+ impact: MEDIUM
4
+ impactDescription: 2-10x better query plans with accurate statistics
5
+ tags: vacuum, analyze, statistics, maintenance, autovacuum
6
+ ---
7
+
8
+ ## Maintain Table Statistics with VACUUM and ANALYZE
9
+
10
+ Outdated statistics cause the query planner to make poor decisions. VACUUM reclaims space, ANALYZE updates statistics.
11
+
12
+ **Incorrect (stale statistics):**
13
+
14
+ ```sql
15
+ -- Table has 1M rows but stats say 1000
16
+ -- Query planner chooses wrong strategy
17
+ explain select * from orders where status = 'pending';
18
+ -- Shows: Seq Scan (because stats show small table)
19
+ -- Actually: Index Scan would be much faster
20
+ ```
21
+
22
+ **Correct (maintain fresh statistics):**
23
+
24
+ ```sql
25
+ -- Manually analyze after large data changes
26
+ analyze orders;
27
+
28
+ -- Analyze specific columns used in WHERE clauses
29
+ analyze orders (status, created_at);
30
+
31
+ -- Check when tables were last analyzed
32
+ select
33
+ relname,
34
+ last_vacuum,
35
+ last_autovacuum,
36
+ last_analyze,
37
+ last_autoanalyze
38
+ from pg_stat_user_tables
39
+ order by last_analyze nulls first;
40
+ ```
41
+
42
+ Autovacuum tuning for busy tables:
43
+
44
+ ```sql
45
+ -- Increase frequency for high-churn tables
46
+ alter table orders set (
47
+ autovacuum_vacuum_scale_factor = 0.05, -- Vacuum at 5% dead tuples (default 20%)
48
+ autovacuum_analyze_scale_factor = 0.02 -- Analyze at 2% changes (default 10%)
49
+ );
50
+
51
+ -- Check autovacuum status
52
+ select * from pg_stat_progress_vacuum;
53
+ ```
54
+
55
+ Reference: [VACUUM](https://supabase.com/docs/guides/database/database-size#vacuum-operations)
@@ -1,44 +1,44 @@
1
- ---
2
- title: Create Composite Indexes for Multi-Column Queries
3
- impact: HIGH
4
- impactDescription: 5-10x faster multi-column queries
5
- tags: indexes, composite-index, multi-column, query-optimization
6
- ---
7
-
8
- ## Create Composite Indexes for Multi-Column Queries
9
-
10
- When queries filter on multiple columns, a composite index is more efficient than separate single-column indexes.
11
-
12
- **Incorrect (separate indexes require bitmap scan):**
13
-
14
- ```sql
15
- -- Two separate indexes
16
- create index orders_status_idx on orders (status);
17
- create index orders_created_idx on orders (created_at);
18
-
19
- -- Query must combine both indexes (slower)
20
- select * from orders where status = 'pending' and created_at > '2024-01-01';
21
- ```
22
-
23
- **Correct (composite index):**
24
-
25
- ```sql
26
- -- Single composite index (leftmost column first for equality checks)
27
- create index orders_status_created_idx on orders (status, created_at);
28
-
29
- -- Query uses one efficient index scan
30
- select * from orders where status = 'pending' and created_at > '2024-01-01';
31
- ```
32
-
33
- **Column order matters** - place equality columns first, range columns last:
34
-
35
- ```sql
36
- -- Good: status (=) before created_at (>)
37
- create index idx on orders (status, created_at);
38
-
39
- -- Works for: WHERE status = 'pending'
40
- -- Works for: WHERE status = 'pending' AND created_at > '2024-01-01'
41
- -- Does NOT work for: WHERE created_at > '2024-01-01' (leftmost prefix rule)
42
- ```
43
-
44
- Reference: [Multicolumn Indexes](https://www.postgresql.org/docs/current/indexes-multicolumn.html)
1
+ ---
2
+ title: Create Composite Indexes for Multi-Column Queries
3
+ impact: HIGH
4
+ impactDescription: 5-10x faster multi-column queries
5
+ tags: indexes, composite-index, multi-column, query-optimization
6
+ ---
7
+
8
+ ## Create Composite Indexes for Multi-Column Queries
9
+
10
+ When queries filter on multiple columns, a composite index is more efficient than separate single-column indexes.
11
+
12
+ **Incorrect (separate indexes require bitmap scan):**
13
+
14
+ ```sql
15
+ -- Two separate indexes
16
+ create index orders_status_idx on orders (status);
17
+ create index orders_created_idx on orders (created_at);
18
+
19
+ -- Query must combine both indexes (slower)
20
+ select * from orders where status = 'pending' and created_at > '2024-01-01';
21
+ ```
22
+
23
+ **Correct (composite index):**
24
+
25
+ ```sql
26
+ -- Single composite index (leftmost column first for equality checks)
27
+ create index orders_status_created_idx on orders (status, created_at);
28
+
29
+ -- Query uses one efficient index scan
30
+ select * from orders where status = 'pending' and created_at > '2024-01-01';
31
+ ```
32
+
33
+ **Column order matters** - place equality columns first, range columns last:
34
+
35
+ ```sql
36
+ -- Good: status (=) before created_at (>)
37
+ create index idx on orders (status, created_at);
38
+
39
+ -- Works for: WHERE status = 'pending'
40
+ -- Works for: WHERE status = 'pending' AND created_at > '2024-01-01'
41
+ -- Does NOT work for: WHERE created_at > '2024-01-01' (leftmost prefix rule)
42
+ ```
43
+
44
+ Reference: [Multicolumn Indexes](https://www.postgresql.org/docs/current/indexes-multicolumn.html)
@@ -1,40 +1,40 @@
1
- ---
2
- title: Use Covering Indexes to Avoid Table Lookups
3
- impact: MEDIUM-HIGH
4
- impactDescription: 2-5x faster queries by eliminating heap fetches
5
- tags: indexes, covering-index, include, index-only-scan
6
- ---
7
-
8
- ## Use Covering Indexes to Avoid Table Lookups
9
-
10
- Covering indexes include all columns needed by a query, enabling index-only scans that skip the table entirely.
11
-
12
- **Incorrect (index scan + heap fetch):**
13
-
14
- ```sql
15
- create index users_email_idx on users (email);
16
-
17
- -- Must fetch name and created_at from table heap
18
- select email, name, created_at from users where email = 'user@example.com';
19
- ```
20
-
21
- **Correct (index-only scan with INCLUDE):**
22
-
23
- ```sql
24
- -- Include non-searchable columns in the index
25
- create index users_email_idx on users (email) include (name, created_at);
26
-
27
- -- All columns served from index, no table access needed
28
- select email, name, created_at from users where email = 'user@example.com';
29
- ```
30
-
31
- Use INCLUDE for columns you SELECT but don't filter on:
32
-
33
- ```sql
34
- -- Searching by status, but also need customer_id and total
35
- create index orders_status_idx on orders (status) include (customer_id, total);
36
-
37
- select status, customer_id, total from orders where status = 'shipped';
38
- ```
39
-
40
- Reference: [Index-Only Scans](https://www.postgresql.org/docs/current/indexes-index-only-scans.html)
1
+ ---
2
+ title: Use Covering Indexes to Avoid Table Lookups
3
+ impact: MEDIUM-HIGH
4
+ impactDescription: 2-5x faster queries by eliminating heap fetches
5
+ tags: indexes, covering-index, include, index-only-scan
6
+ ---
7
+
8
+ ## Use Covering Indexes to Avoid Table Lookups
9
+
10
+ Covering indexes include all columns needed by a query, enabling index-only scans that skip the table entirely.
11
+
12
+ **Incorrect (index scan + heap fetch):**
13
+
14
+ ```sql
15
+ create index users_email_idx on users (email);
16
+
17
+ -- Must fetch name and created_at from table heap
18
+ select email, name, created_at from users where email = 'user@example.com';
19
+ ```
20
+
21
+ **Correct (index-only scan with INCLUDE):**
22
+
23
+ ```sql
24
+ -- Include non-searchable columns in the index
25
+ create index users_email_idx on users (email) include (name, created_at);
26
+
27
+ -- All columns served from index, no table access needed
28
+ select email, name, created_at from users where email = 'user@example.com';
29
+ ```
30
+
31
+ Use INCLUDE for columns you SELECT but don't filter on:
32
+
33
+ ```sql
34
+ -- Searching by status, but also need customer_id and total
35
+ create index orders_status_idx on orders (status) include (customer_id, total);
36
+
37
+ select status, customer_id, total from orders where status = 'shipped';
38
+ ```
39
+
40
+ Reference: [Index-Only Scans](https://www.postgresql.org/docs/current/indexes-index-only-scans.html)
@@ -1,48 +1,48 @@
1
- ---
2
- title: Choose the Right Index Type for Your Data
3
- impact: HIGH
4
- impactDescription: 10-100x improvement with correct index type
5
- tags: indexes, btree, gin, gist, brin, hash, index-types
6
- ---
7
-
8
- ## Choose the Right Index Type for Your Data
9
-
10
- Different index types excel at different query patterns. The default B-tree isn't always optimal.
11
-
12
- **Incorrect (B-tree for JSONB containment):**
13
-
14
- ```sql
15
- -- B-tree cannot optimize containment operators
16
- create index products_attrs_idx on products (attributes);
17
- select * from products where attributes @> '{"color": "red"}';
18
- -- Full table scan - B-tree doesn't support @> operator
19
- ```
20
-
21
- **Correct (GIN for JSONB):**
22
-
23
- ```sql
24
- -- GIN supports @>, ?, ?&, ?| operators
25
- create index products_attrs_idx on products using gin (attributes);
26
- select * from products where attributes @> '{"color": "red"}';
27
- ```
28
-
29
- Index type guide:
30
-
31
- ```sql
32
- -- B-tree (default): =, <, >, BETWEEN, IN, IS NULL
33
- create index users_created_idx on users (created_at);
34
-
35
- -- GIN: arrays, JSONB, full-text search
36
- create index posts_tags_idx on posts using gin (tags);
37
-
38
- -- GiST: geometric data, range types, nearest-neighbor (KNN) queries
39
- create index locations_idx on places using gist (location);
40
-
41
- -- BRIN: large time-series tables (10-100x smaller)
42
- create index events_time_idx on events using brin (created_at);
43
-
44
- -- Hash: equality-only (slightly faster than B-tree for =)
45
- create index sessions_token_idx on sessions using hash (token);
46
- ```
47
-
48
- Reference: [Index Types](https://www.postgresql.org/docs/current/indexes-types.html)
1
+ ---
2
+ title: Choose the Right Index Type for Your Data
3
+ impact: HIGH
4
+ impactDescription: 10-100x improvement with correct index type
5
+ tags: indexes, btree, gin, gist, brin, hash, index-types
6
+ ---
7
+
8
+ ## Choose the Right Index Type for Your Data
9
+
10
+ Different index types excel at different query patterns. The default B-tree isn't always optimal.
11
+
12
+ **Incorrect (B-tree for JSONB containment):**
13
+
14
+ ```sql
15
+ -- B-tree cannot optimize containment operators
16
+ create index products_attrs_idx on products (attributes);
17
+ select * from products where attributes @> '{"color": "red"}';
18
+ -- Full table scan - B-tree doesn't support @> operator
19
+ ```
20
+
21
+ **Correct (GIN for JSONB):**
22
+
23
+ ```sql
24
+ -- GIN supports @>, ?, ?&, ?| operators
25
+ create index products_attrs_idx on products using gin (attributes);
26
+ select * from products where attributes @> '{"color": "red"}';
27
+ ```
28
+
29
+ Index type guide:
30
+
31
+ ```sql
32
+ -- B-tree (default): =, <, >, BETWEEN, IN, IS NULL
33
+ create index users_created_idx on users (created_at);
34
+
35
+ -- GIN: arrays, JSONB, full-text search
36
+ create index posts_tags_idx on posts using gin (tags);
37
+
38
+ -- GiST: geometric data, range types, nearest-neighbor (KNN) queries
39
+ create index locations_idx on places using gist (location);
40
+
41
+ -- BRIN: large time-series tables (10-100x smaller)
42
+ create index events_time_idx on events using brin (created_at);
43
+
44
+ -- Hash: equality-only (slightly faster than B-tree for =)
45
+ create index sessions_token_idx on sessions using hash (token);
46
+ ```
47
+
48
+ Reference: [Index Types](https://www.postgresql.org/docs/current/indexes-types.html)
@@ -1,43 +1,43 @@
1
- ---
2
- title: Add Indexes on WHERE and JOIN Columns
3
- impact: CRITICAL
4
- impactDescription: 100-1000x faster queries on large tables
5
- tags: indexes, performance, sequential-scan, query-optimization
6
- ---
7
-
8
- ## Add Indexes on WHERE and JOIN Columns
9
-
10
- Queries filtering or joining on unindexed columns cause full table scans, which become exponentially slower as tables grow.
11
-
12
- **Incorrect (sequential scan on large table):**
13
-
14
- ```sql
15
- -- No index on customer_id causes full table scan
16
- select * from orders where customer_id = 123;
17
-
18
- -- EXPLAIN shows: Seq Scan on orders (cost=0.00..25000.00 rows=100 width=85)
19
- ```
20
-
21
- **Correct (index scan):**
22
-
23
- ```sql
24
- -- Create index on frequently filtered column
25
- create index orders_customer_id_idx on orders (customer_id);
26
-
27
- select * from orders where customer_id = 123;
28
-
29
- -- EXPLAIN shows: Index Scan using orders_customer_id_idx (cost=0.42..8.44 rows=100 width=85)
30
- ```
31
-
32
- For JOIN columns, always index the foreign key side:
33
-
34
- ```sql
35
- -- Index the referencing column
36
- create index orders_customer_id_idx on orders (customer_id);
37
-
38
- select c.name, o.total
39
- from customers c
40
- join orders o on o.customer_id = c.id;
41
- ```
42
-
43
- Reference: [Query Optimization](https://supabase.com/docs/guides/database/query-optimization)
1
+ ---
2
+ title: Add Indexes on WHERE and JOIN Columns
3
+ impact: CRITICAL
4
+ impactDescription: 100-1000x faster queries on large tables
5
+ tags: indexes, performance, sequential-scan, query-optimization
6
+ ---
7
+
8
+ ## Add Indexes on WHERE and JOIN Columns
9
+
10
+ Queries filtering or joining on unindexed columns cause full table scans, which become exponentially slower as tables grow.
11
+
12
+ **Incorrect (sequential scan on large table):**
13
+
14
+ ```sql
15
+ -- No index on customer_id causes full table scan
16
+ select * from orders where customer_id = 123;
17
+
18
+ -- EXPLAIN shows: Seq Scan on orders (cost=0.00..25000.00 rows=100 width=85)
19
+ ```
20
+
21
+ **Correct (index scan):**
22
+
23
+ ```sql
24
+ -- Create index on frequently filtered column
25
+ create index orders_customer_id_idx on orders (customer_id);
26
+
27
+ select * from orders where customer_id = 123;
28
+
29
+ -- EXPLAIN shows: Index Scan using orders_customer_id_idx (cost=0.42..8.44 rows=100 width=85)
30
+ ```
31
+
32
+ For JOIN columns, always index the foreign key side:
33
+
34
+ ```sql
35
+ -- Index the referencing column
36
+ create index orders_customer_id_idx on orders (customer_id);
37
+
38
+ select c.name, o.total
39
+ from customers c
40
+ join orders o on o.customer_id = c.id;
41
+ ```
42
+
43
+ Reference: [Query Optimization](https://supabase.com/docs/guides/database/query-optimization)