tasks for 4
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run the 10k-row message history plan probe inside a rolled-back transaction."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
sql = (root / 'scripts' / 'explain_message_history.sql').read_text(encoding='utf-8')
|
||||
result = subprocess.run(
|
||||
[
|
||||
'docker', 'compose', '--env-file', '.env', 'exec', '-T', 'postgres',
|
||||
'sh', '-lc', 'psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
|
||||
],
|
||||
cwd=root,
|
||||
input=sql,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False,
|
||||
)
|
||||
print(result.stdout, end='')
|
||||
if result.returncode != 0:
|
||||
raise SystemExit(result.returncode)
|
||||
plan = result.stdout[result.stdout.find('QUERY PLAN'):]
|
||||
if 'Index Scan' not in plan or 'messages_chat_created_id_idx' not in plan:
|
||||
raise SystemExit('FAIL: expected messages_chat_created_id_idx index scan')
|
||||
if 'Seq Scan on messages' in plan:
|
||||
raise SystemExit('FAIL: message history used a sequential scan')
|
||||
print('PASS: 10,000-row keyset page used messages_chat_created_id_idx without a full scan.')
|
||||
@@ -0,0 +1,47 @@
|
||||
BEGIN;
|
||||
|
||||
INSERT INTO users (id, username, display_name, password_hash, created_at)
|
||||
VALUES (
|
||||
'70000000-0000-4000-8000-000000000001',
|
||||
'explain_probe',
|
||||
'EXPLAIN probe',
|
||||
'$argon2id$v=19$m=16384,t=2,p=1$probe$probe',
|
||||
'2026-01-01T00:00:00Z'
|
||||
);
|
||||
|
||||
INSERT INTO chats (id, title, created_at)
|
||||
VALUES (
|
||||
'70000000-0000-4000-8000-000000000002',
|
||||
'EXPLAIN history probe',
|
||||
'2026-01-01T00:00:00Z'
|
||||
);
|
||||
|
||||
INSERT INTO chat_members (chat_id, user_id)
|
||||
VALUES (
|
||||
'70000000-0000-4000-8000-000000000002',
|
||||
'70000000-0000-4000-8000-000000000001'
|
||||
);
|
||||
|
||||
INSERT INTO messages (id, chat_id, sender_id, text, created_at)
|
||||
SELECT
|
||||
('70000000-0000-4000-8000-' || lpad(series::text, 12, '0'))::uuid,
|
||||
'70000000-0000-4000-8000-000000000002'::uuid,
|
||||
'70000000-0000-4000-8000-000000000001'::uuid,
|
||||
'history probe ' || series,
|
||||
'2026-01-01T00:00:00Z'::timestamptz + series * interval '1 millisecond'
|
||||
FROM generate_series(1, 10000) AS series;
|
||||
|
||||
ANALYZE messages;
|
||||
|
||||
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
|
||||
SELECT id, chat_id, sender_id, text, created_at
|
||||
FROM messages
|
||||
WHERE chat_id = '70000000-0000-4000-8000-000000000002'::uuid
|
||||
AND (created_at, id) > (
|
||||
'2026-01-01T00:00:05Z'::timestamptz,
|
||||
'70000000-0000-4000-8000-000000005000'::uuid
|
||||
)
|
||||
ORDER BY created_at, id
|
||||
LIMIT 100;
|
||||
|
||||
ROLLBACK;
|
||||
Regular → Executable
+2
-2
@@ -2,5 +2,5 @@
|
||||
set -eu
|
||||
|
||||
# Restart every stateful component used by the application without deleting the
|
||||
# named PostgreSQL volume. The persistence test waits for readiness afterwards.
|
||||
docker compose --env-file .env restart postgres api
|
||||
# named PostgreSQL/Redis volumes. The persistence test waits for readiness afterwards.
|
||||
docker compose --env-file .env restart postgres redis api
|
||||
|
||||
Reference in New Issue
Block a user