forked from mtusi2026/mtusi2026lab2
Implement messenger functionality
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
BEGIN;
|
||||
CREATE TEMP TABLE lab_messages (
|
||||
id UUID NOT NULL,
|
||||
chat_id INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
text VARCHAR(4000) NOT NULL
|
||||
);
|
||||
CREATE INDEX lab_messages_history_idx ON lab_messages(chat_id, created_at, id);
|
||||
INSERT INTO lab_messages(id, chat_id, created_at, text)
|
||||
SELECT md5(g::text)::uuid,
|
||||
CASE WHEN g <= 10000 THEN 1 ELSE 2 + (g % 100) END,
|
||||
TIMESTAMPTZ '2026-01-01 00:00:00+00' + g * INTERVAL '1 millisecond',
|
||||
repeat('x', 40)
|
||||
FROM generate_series(1, 100000) AS g;
|
||||
ANALYZE lab_messages;
|
||||
EXPLAIN (ANALYZE, BUFFERS)
|
||||
SELECT id, chat_id, created_at, text
|
||||
FROM lab_messages
|
||||
WHERE chat_id = 1
|
||||
AND (created_at, id) > (TIMESTAMPTZ '2026-01-01 00:00:05+00', md5('5000')::uuid)
|
||||
ORDER BY created_at, id
|
||||
LIMIT 50;
|
||||
ROLLBACK;
|
||||
Reference in New Issue
Block a user