forked from mtusi2026/mtusi2026lab2
Fix cached session identity and document PR 63 regression checks
This commit is contained in:
@@ -18,13 +18,9 @@ def main() -> None:
|
||||
cur.execute("INSERT INTO chat_members(chat_id, user_id) VALUES (%s, %s)", (chat_id, user_id))
|
||||
for idx in range(10000):
|
||||
cur.execute(
|
||||
"INSERT INTO messages(id, chat_id, sender_id, text, created_at) VALUES (%s, %s, %s, %s, NOW() - INTERVAL '%s milliseconds')",
|
||||
"INSERT INTO messages(id, chat_id, sender_id, text, created_at) VALUES (%s, %s, %s, %s, NOW() - %s * INTERVAL '1 millisecond')",
|
||||
(uuid.uuid4(), chat_id, user_id, f"msg-{idx}", idx),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
cursor_ts = "2100-01-01T00:00:00Z"
|
||||
cursor_id = str(uuid.uuid4())
|
||||
explain_sql = """
|
||||
EXPLAIN (ANALYZE, BUFFERS)
|
||||
SELECT id, chat_id, sender_id, text, created_at
|
||||
@@ -32,12 +28,16 @@ def main() -> None:
|
||||
WHERE chat_id = %s
|
||||
AND (created_at, id) > (%s::timestamptz, %s::uuid)
|
||||
ORDER BY created_at ASC, id ASC
|
||||
LIMIT 1
|
||||
LIMIT 51
|
||||
"""
|
||||
cur.execute(explain_sql, (chat_id, cursor_ts, cursor_id))
|
||||
plan = cur.fetchall()
|
||||
|
||||
print("\n".join(row[0] for row in plan))
|
||||
for offset in (0, 5000, 9900):
|
||||
cur.execute("SELECT created_at, id FROM messages WHERE chat_id = %s ORDER BY created_at, id OFFSET %s LIMIT 1", (chat_id, offset))
|
||||
cursor_ts, cursor_id = cur.fetchone()
|
||||
cur.execute(explain_sql, (chat_id, cursor_ts, cursor_id))
|
||||
print(f"Page after position {offset}:")
|
||||
print("\n".join(row[0] for row in cur.fetchall()))
|
||||
# Keep the measurement repeatable without accumulating fixtures.
|
||||
conn.rollback()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user