3.28.2: Оптимизация загрузки деталей задачи
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m44s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m44s
This commit is contained in:
14
play-life-backend/migrations/028_optimize_task_queries.sql
Normal file
14
play-life-backend/migrations/028_optimize_task_queries.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Migration: Optimize task queries with composite index
|
||||
-- Date: 2026-01-24
|
||||
--
|
||||
-- This migration adds a composite index to optimize the task detail query:
|
||||
-- WHERE id = $1 AND user_id = $2 AND deleted = FALSE
|
||||
--
|
||||
-- The index uses a partial index with WHERE deleted = FALSE to reduce index size
|
||||
-- and improve query performance for active (non-deleted) tasks.
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_tasks_id_user_deleted
|
||||
ON tasks(id, user_id, deleted)
|
||||
WHERE deleted = FALSE;
|
||||
|
||||
COMMENT ON INDEX idx_tasks_id_user_deleted IS 'Composite index for optimizing task detail queries with id, user_id, and deleted filter. Partial index for non-deleted tasks only.';
|
||||
25
play-life-backend/migrations/029_add_covering_indexes.sql
Normal file
25
play-life-backend/migrations/029_add_covering_indexes.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Migration: Add covering indexes for task detail queries
|
||||
-- Date: 2026-01-25
|
||||
--
|
||||
-- This migration adds covering indexes to optimize queries by including
|
||||
-- all needed columns in the index, avoiding table lookups.
|
||||
--
|
||||
-- Covering indexes allow PostgreSQL to perform index-only scans,
|
||||
-- getting all data directly from the index without accessing the table.
|
||||
|
||||
-- Covering index for subtasks query
|
||||
-- Includes all columns needed for subtasks selection to avoid table lookups
|
||||
CREATE INDEX IF NOT EXISTS idx_tasks_parent_deleted_covering
|
||||
ON tasks(parent_task_id, deleted, id)
|
||||
INCLUDE (name, completed, last_completed_at, reward_message, progression_base)
|
||||
WHERE deleted = FALSE;
|
||||
|
||||
-- Covering index for wishlist name lookup
|
||||
-- Includes name and deleted flag for quick lookup without table access
|
||||
CREATE INDEX IF NOT EXISTS idx_wishlist_items_id_deleted_covering
|
||||
ON wishlist_items(id, deleted)
|
||||
INCLUDE (name)
|
||||
WHERE deleted = FALSE;
|
||||
|
||||
COMMENT ON INDEX idx_tasks_parent_deleted_covering IS 'Covering index for subtasks query - includes all selected columns to avoid table lookups. Enables index-only scans for better performance.';
|
||||
COMMENT ON INDEX idx_wishlist_items_id_deleted_covering IS 'Covering index for wishlist name lookup - includes name to avoid table lookup. Enables index-only scans for better performance.';
|
||||
Reference in New Issue
Block a user