forked from mtusi2026/mtusi2026lab2
8 lines
622 B
Plaintext
8 lines
622 B
Plaintext
-- Профиль чтения: страница истории большого чата с курсором случайной глубины (keyset), LIMIT 51 как в API (limit=50 + 1).
|
|
-- Параметры: -D big='uuid' -D ncur=<число курсоров в bench.cursors>.
|
|
\set k random(1, :ncur)
|
|
SELECT quote_literal(t::text) AS ct, quote_literal(id::text) AS cid FROM bench.cursors WHERE n = :k \gset
|
|
SELECT m.id, m.chat_id, m.created_at, m.sender_id, m.text
|
|
FROM (SELECT * FROM messages WHERE chat_id = :big AND (created_at, id) > (:ct::timestamptz, :cid::uuid)) AS m
|
|
ORDER BY m.created_at, m.id LIMIT 51;
|