48 lines
1.3 KiB
PL/PgSQL
48 lines
1.3 KiB
PL/PgSQL
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;
|