diff --git a/Makefile b/Makefile index 4c6df3c3..8a166660 100644 --- a/Makefile +++ b/Makefile @@ -38,3 +38,7 @@ level4-test: explain: $(PYTHON) student-tests/explain_level4.py + +.PHONY: research +research: + $(PYTHON) scripts/research.py diff --git a/evidence/recovery.json b/evidence/recovery.json new file mode 100644 index 00000000..db2e8362 --- /dev/null +++ b/evidence/recovery.json @@ -0,0 +1,387 @@ +{ + "source_database": "lab2_research_eaaceacf5e", + "restore_container": "lyakhonov-lab2-restore-e73b5fd47f", + "new_volume": "lyakhonov_lab2_restore_e73b5fd47f", + "archive_file": "backups/research_fb31d8e86c.dump", + "archive_bytes": 2991247, + "backup_seconds": 1.3044416999910027, + "restore_seconds": 0.8138425000070129, + "provision_and_restore_seconds": 3.1661540000059176, + "checks": { + "counts": { + "equal": true, + "value": { + "users": 1, + "chats": 13, + "members": 13, + "messages": 100000, + "sessions": 0 + } + }, + "all_message_fingerprint": { + "equal": true, + "value": { + "count": 100000, + "digest": "1e61a199fa8e8c94d2041f6f64394fd9" + } + }, + "selected_messages": { + "equal": true, + "value": [ + { + "id": "11a3b161-4e2b-4aaf-a4cd-12e9d57edf52", + "chat_id": "0895b1b6-473e-41be-8ea1-bf81a723fadc", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "99be4627-2bc0-45ac-b505-402cd8a12693", + "chat_id": "0895b1b6-473e-41be-8ea1-bf81a723fadc", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "9d3e23a8-69f2-42c8-bb78-ae97911aa7d5", + "chat_id": "0895b1b6-473e-41be-8ea1-bf81a723fadc", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "04348821-e05f-46fe-b5b1-e2e11bd7645e", + "chat_id": "11981599-4a94-4007-bd54-201527ddad8a", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "6e87c8e2-6b8e-46f1-9718-9f4c8e1c40c8", + "chat_id": "11981599-4a94-4007-bd54-201527ddad8a", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "e2b6195d-91e1-44bd-b213-91c5db1032b2", + "chat_id": "11981599-4a94-4007-bd54-201527ddad8a", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "4d2ca458-a710-4764-bf18-149495dca55e", + "chat_id": "1605ec06-2fcb-4281-84ff-a3da632735a3", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "7474c834-f59e-4fed-923a-33f0dc1d4cda", + "chat_id": "1605ec06-2fcb-4281-84ff-a3da632735a3", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "96a0e5d8-1361-4377-9c20-ebb719a78905", + "chat_id": "1605ec06-2fcb-4281-84ff-a3da632735a3", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "12ebdc82-c91d-48f9-92c2-88b1a0bd1c58", + "chat_id": "3c405a3b-6a05-44db-b95b-bf169588af8e", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "98dc824d-2eab-439c-bb32-2dab06e1a0a9", + "chat_id": "3c405a3b-6a05-44db-b95b-bf169588af8e", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "d46c72a5-ad44-43e7-82e2-4a4bbd7f516e", + "chat_id": "3c405a3b-6a05-44db-b95b-bf169588af8e", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "537239af-3ae3-4c63-8ca7-15ad966e462d", + "chat_id": "435b684f-92c0-4429-b392-f610a4eb2c1d", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "755c5e7d-a3c7-4232-b96b-4cb19954385a", + "chat_id": "435b684f-92c0-4429-b392-f610a4eb2c1d", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "efa11b0f-c8b1-4201-8b70-ae4f05e850ea", + "chat_id": "435b684f-92c0-4429-b392-f610a4eb2c1d", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "0318ba50-7912-4975-9960-17a2710d753c", + "chat_id": "43c99015-4e1d-46c4-8a29-369516c20985", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx20000", + "created_at": "2026-01-01T00:00:00.02+00:00", + "n": 20000, + "total": 20000 + }, + { + "id": "4f3a53b1-59c5-49db-808f-d7237d18ffbc", + "chat_id": "43c99015-4e1d-46c4-8a29-369516c20985", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx10000", + "created_at": "2026-01-01T00:00:00.01+00:00", + "n": 10000, + "total": 20000 + }, + { + "id": "575e59bf-fef2-49c4-8274-67d4c26de49a", + "chat_id": "43c99015-4e1d-46c4-8a29-369516c20985", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 20000 + }, + { + "id": "2417d232-3b20-492e-bcb9-28570446ac1f", + "chat_id": "44747c11-d90a-436f-9ec0-a01325912444", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "9ecb8a28-faa5-4210-bfdf-8f2ed309a519", + "chat_id": "44747c11-d90a-436f-9ec0-a01325912444", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "dcada8e5-4af5-454c-953b-0556c7c73267", + "chat_id": "44747c11-d90a-436f-9ec0-a01325912444", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "1a6103ab-bb23-4cba-b0dd-bd7c133c63b8", + "chat_id": "474412a5-c1a5-48f3-a2cf-044f2cfe4f12", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "9e226f91-9251-4948-8969-c3d7a829d619", + "chat_id": "474412a5-c1a5-48f3-a2cf-044f2cfe4f12", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "c298525a-c3df-46a6-9069-4f74f069618c", + "chat_id": "474412a5-c1a5-48f3-a2cf-044f2cfe4f12", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "088bcd80-4186-464a-9cbd-524e5ccf9704", + "chat_id": "91ff03f5-fc06-4689-99ea-5ac69a0c7bd6", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "69508dfb-9024-4064-8fbc-223f5acf1b11", + "chat_id": "91ff03f5-fc06-4689-99ea-5ac69a0c7bd6", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "a5ad8ac2-9687-45b6-9ee0-5bcb80e44a74", + "chat_id": "91ff03f5-fc06-4689-99ea-5ac69a0c7bd6", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "122852f1-d8c3-46fe-ac29-14e6cfc3272e", + "chat_id": "bdd3477c-67e1-4dc1-ad42-3e2551db823b", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "4447d2e4-6e92-43a3-9b08-573f879f1e99", + "chat_id": "bdd3477c-67e1-4dc1-ad42-3e2551db823b", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "47e6b656-df1d-4930-a049-4879c02614ed", + "chat_id": "bdd3477c-67e1-4dc1-ad42-3e2551db823b", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + }, + { + "id": "642c52a5-b8a1-4ba0-afb9-4fcea0dd65e8", + "chat_id": "c9f802fd-c998-4180-9ca3-f02977eb8301", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx70000", + "created_at": "2026-01-01T00:00:00.07+00:00", + "n": 70000, + "total": 70000 + }, + { + "id": "c92030c9-7b9d-496b-8bea-e57930fc84bb", + "chat_id": "c9f802fd-c998-4180-9ca3-f02977eb8301", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 70000 + }, + { + "id": "dcb218a5-0bc6-4467-9927-e214a027e99f", + "chat_id": "c9f802fd-c998-4180-9ca3-f02977eb8301", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx35000", + "created_at": "2026-01-01T00:00:00.035+00:00", + "n": 35000, + "total": 70000 + }, + { + "id": "2f174ebf-4835-402f-a957-8630ad4d73cc", + "chat_id": "ee38cff2-be26-4a0d-97b7-9d4102096aba", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 9000 + }, + { + "id": "3ae8e884-e4e0-491a-8566-4ba3736ba420", + "chat_id": "ee38cff2-be26-4a0d-97b7-9d4102096aba", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9000", + "created_at": "2026-01-01T00:00:00.009+00:00", + "n": 9000, + "total": 9000 + }, + { + "id": "c48eb0d5-ef04-4689-a289-280bc6fb6ada", + "chat_id": "ee38cff2-be26-4a0d-97b7-9d4102096aba", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4500", + "created_at": "2026-01-01T00:00:00.0045+00:00", + "n": 4500, + "total": 9000 + }, + { + "id": "af1bef3d-5153-42dd-b1cf-8396160e0e7e", + "chat_id": "fcdaf99f-f7b3-4168-944e-a215d7c03e17", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50", + "created_at": "2026-01-01T00:00:00.00005+00:00", + "n": 50, + "total": 100 + }, + { + "id": "b237f587-49fc-4b04-883c-e246450992e4", + "chat_id": "fcdaf99f-f7b3-4168-944e-a215d7c03e17", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1", + "created_at": "2026-01-01T00:00:00.000001+00:00", + "n": 1, + "total": 100 + }, + { + "id": "f2dc8d6b-e8dd-455e-90d2-b144d10bd6c8", + "chat_id": "fcdaf99f-f7b3-4168-944e-a215d7c03e17", + "sender_id": "dd797d22-94f6-4dd0-b9e2-64ceb3d6d5d1", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx100", + "created_at": "2026-01-01T00:00:00.0001+00:00", + "n": 100, + "total": 100 + } + ] + } + }, + "snapshot_message_loss": 0, + "passed": true +} diff --git a/evidence/research.json b/evidence/research.json new file mode 100644 index 00000000..bbe2ad0e --- /dev/null +++ b/evidence/research.json @@ -0,0 +1,3878 @@ +{ + "database": "lab2_research_eaaceacf5e", + "rows": 100000, + "chat_sizes": [ + 70000, + 20000, + 9000, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100 + ], + "seed_seconds": 5.309577420000096, + "concurrency": 1, + "warmup_queries_per_case": 3, + "queries_per_case": 100, + "repeats_write": 3, + "variants": [ + { + "name": "chat_only", + "ddl": "CREATE INDEX research_idx ON messages(chat_id)", + "build_seconds": 0.07175255599986485, + "index_bytes": 737280, + "write_1000_commit_seconds": [ + 0.04581827099991642, + 0.05066664200012383, + 0.05026085800000146 + ], + "write_median_rows_per_second": 19896.19834981669, + "cases": [ + { + "chat_size": 70000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.9803247230011038, + "successful_rps": 102.00701630156419, + "p50_ms": 9.210211000208801, + "p95_ms": 11.736868000298273, + "p99_ms": 28.171970999665064, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 5908.64, + "Total Cost": 5914.51, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 7.038, + "Actual Total Time": 8.725, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2826, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Gather Merge", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 5908.64, + "Total Cost": 9590.83, + "Plan Rows": 32019, + "Plan Width": 192, + "Actual Startup Time": 7.036, + "Actual Total Time": 8.72, + "Actual Rows": 51, + "Actual Loops": 1, + "Workers Planned": 1, + "Workers Launched": 1, + "Shared Hit Blocks": 2826, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4908.63, + "Total Cost": 4988.68, + "Plan Rows": 32019, + "Plan Width": 192, + "Actual Startup Time": 5.02, + "Actual Total Time": 5.022, + "Actual Rows": 51, + "Actual Loops": 2, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2826, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Workers": [ + { + "Worker Number": 0, + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory" + } + ], + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": true, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.0, + "Total Cost": 3840.41, + "Plan Rows": 32019, + "Plan Width": 192, + "Actual Startup Time": 0.184, + "Actual Total Time": 3.223, + "Actual Rows": 31500, + "Actual Loops": 2, + "Filter": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.007001+00'::timestamp with time zone, '80faa22b-17f0-494e-8a8f-c9cf7b79c163'::uuid)))", + "Rows Removed by Filter": 18500, + "Shared Hit Blocks": 2811, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Workers": [] + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.101, + "Triggers": [], + "Execution Time": 8.759 + } + }, + { + "chat_size": 70000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.8387598000008438, + "successful_rps": 119.22364424224837, + "p50_ms": 8.166588999756641, + "p95_ms": 10.050038000372297, + "p99_ms": 13.36698900013289, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 5318.6, + "Total Cost": 5324.47, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 7.255, + "Actual Total Time": 9.249, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2826, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Gather Merge", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 5318.6, + "Total Cost": 6966.9, + "Plan Rows": 14333, + "Plan Width": 192, + "Actual Startup Time": 7.179, + "Actual Total Time": 9.169, + "Actual Rows": 51, + "Actual Loops": 1, + "Workers Planned": 1, + "Workers Launched": 1, + "Shared Hit Blocks": 2826, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4318.59, + "Total Cost": 4354.42, + "Plan Rows": 14333, + "Plan Width": 192, + "Actual Startup Time": 4.979, + "Actual Total Time": 4.984, + "Actual Rows": 51, + "Actual Loops": 2, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2826, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Workers": [ + { + "Worker Number": 0, + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory" + } + ], + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": true, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.0, + "Total Cost": 3840.41, + "Plan Rows": 14333, + "Plan Width": 192, + "Actual Startup Time": 1.094, + "Actual Total Time": 3.713, + "Actual Rows": 17500, + "Actual Loops": 2, + "Filter": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.035001+00'::timestamp with time zone, '8c6bb688-4bf1-48bc-b8c4-d383944c3cb5'::uuid)))", + "Rows Removed by Filter": 32500, + "Shared Hit Blocks": 2811, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Workers": [] + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.077, + "Triggers": [], + "Execution Time": 9.29 + } + }, + { + "chat_size": 70000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.692634459000601, + "successful_rps": 144.37629936040076, + "p50_ms": 6.72650899969085, + "p95_ms": 8.431450999978551, + "p99_ms": 9.563345999595185, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4724.04, + "Total Cost": 4724.17, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 5.089, + "Actual Total Time": 5.094, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2811, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4724.04, + "Total Cost": 4736.26, + "Plan Rows": 4887, + "Plan Width": 192, + "Actual Startup Time": 5.088, + "Actual Total Time": 5.091, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2811, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.0, + "Total Cost": 4561.0, + "Plan Rows": 4887, + "Plan Width": 192, + "Actual Startup Time": 2.948, + "Actual Total Time": 4.659, + "Actual Rows": 6999, + "Actual Loops": 1, + "Filter": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.063001+00'::timestamp with time zone, '88938e51-1e25-4508-85e5-4c8e47fd3576'::uuid)))", + "Rows Removed by Filter": 93001, + "Shared Hit Blocks": 2811, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.071, + "Triggers": [], + "Execution Time": 5.129 + } + }, + { + "chat_size": 20000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.2993136759987465, + "successful_rps": 334.0976641522347, + "p50_ms": 2.915214000040578, + "p95_ms": 3.7551200002781115, + "p99_ms": 3.944087000036234, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4015.67, + "Total Cost": 4015.8, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 3.095, + "Actual Total Time": 3.101, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4015.67, + "Total Cost": 4062.49, + "Plan Rows": 18727, + "Plan Width": 192, + "Actual Startup Time": 3.094, + "Actual Total Time": 3.098, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 227.85, + "Total Cost": 3390.9, + "Plan Rows": 18727, + "Plan Width": 192, + "Actual Startup Time": 0.44, + "Actual Total Time": 1.935, + "Actual Rows": 17999, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.002001+00'::timestamp with time zone, '01bd6fea-2be5-403c-b230-bdfc889d5730'::uuid))", + "Rows Removed by Filter": 2001, + "Exact Heap Blocks": 557, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 223.17, + "Plan Rows": 20117, + "Plan Width": 0, + "Actual Startup Time": 0.259, + "Actual Total Time": 0.259, + "Actual Rows": 20000, + "Actual Loops": 1, + "Index Cond": "(chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid)", + "Shared Hit Blocks": 19, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.081, + "Triggers": [], + "Execution Time": 3.141 + } + }, + { + "chat_size": 20000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.2553124020028008, + "successful_rps": 391.67701692338073, + "p50_ms": 2.500058000350691, + "p95_ms": 3.0348320001394313, + "p99_ms": 3.411917999983416, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3859.38, + "Total Cost": 3859.5, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 2.257, + "Actual Total Time": 2.264, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3859.38, + "Total Cost": 3894.57, + "Plan Rows": 14077, + "Plan Width": 192, + "Actual Startup Time": 2.257, + "Actual Total Time": 2.261, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 226.69, + "Total Cost": 3389.74, + "Plan Rows": 14077, + "Plan Width": 192, + "Actual Startup Time": 0.75, + "Actual Total Time": 1.678, + "Actual Rows": 9999, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.010001+00'::timestamp with time zone, '758312ad-f300-4498-87fb-4f456e7d7d26'::uuid))", + "Rows Removed by Filter": 10001, + "Exact Heap Blocks": 557, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 223.17, + "Plan Rows": 20117, + "Plan Width": 0, + "Actual Startup Time": 0.227, + "Actual Total Time": 0.228, + "Actual Rows": 20000, + "Actual Loops": 1, + "Index Cond": "(chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid)", + "Shared Hit Blocks": 19, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.071, + "Triggers": [], + "Execution Time": 2.312 + } + }, + { + "chat_size": 20000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.21075914700395515, + "successful_rps": 474.47525491324643, + "p50_ms": 2.042078999693331, + "p95_ms": 2.75955500001146, + "p99_ms": 3.0126440001367882, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3751.11, + "Total Cost": 3751.24, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 1.67, + "Actual Total Time": 1.675, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3751.11, + "Total Cost": 3778.25, + "Plan Rows": 10856, + "Plan Width": 192, + "Actual Startup Time": 1.669, + "Actual Total Time": 1.671, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 225.88, + "Total Cost": 3388.93, + "Plan Rows": 10856, + "Plan Width": 192, + "Actual Startup Time": 1.364, + "Actual Total Time": 1.535, + "Actual Rows": 1999, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.018001+00'::timestamp with time zone, 'f2cea50c-367f-4137-89b1-a168c16b4a7c'::uuid))", + "Rows Removed by Filter": 18001, + "Exact Heap Blocks": 557, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 576, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 223.17, + "Plan Rows": 20117, + "Plan Width": 0, + "Actual Startup Time": 0.261, + "Actual Total Time": 0.261, + "Actual Rows": 20000, + "Actual Loops": 1, + "Index Cond": "(chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid)", + "Shared Hit Blocks": 19, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.079, + "Triggers": [], + "Execution Time": 1.718 + } + }, + { + "chat_size": 9000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.15242807200093011, + "successful_rps": 656.0471354606506, + "p50_ms": 1.433597999948688, + "p95_ms": 2.0341650001682865, + "p99_ms": 2.3047670001687948, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3361.46, + "Total Cost": 3361.59, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 1.561, + "Actual Total Time": 1.572, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3361.46, + "Total Cost": 3383.22, + "Plan Rows": 8705, + "Plan Width": 192, + "Actual Startup Time": 1.559, + "Actual Total Time": 1.565, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 102.14, + "Total Cost": 3071.04, + "Plan Rows": 8705, + "Plan Width": 192, + "Actual Startup Time": 0.187, + "Actual Total Time": 0.998, + "Actual Rows": 8099, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.000901+00'::timestamp with time zone, '57960dbe-3131-4cde-b15a-c90d79b273d6'::uuid))", + "Rows Removed by Filter": 901, + "Exact Heap Blocks": 244, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 99.97, + "Plan Rows": 9023, + "Plan Width": 0, + "Actual Startup Time": 0.105, + "Actual Total Time": 0.106, + "Actual Rows": 9000, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid)", + "Shared Hit Blocks": 10, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.095, + "Triggers": [], + "Execution Time": 1.654 + } + }, + { + "chat_size": 9000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.13607502100194324, + "successful_rps": 734.8887346383135, + "p50_ms": 1.249003000339144, + "p95_ms": 1.894750999781536, + "p99_ms": 2.7906280001843697, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3328.22, + "Total Cost": 3328.35, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.884, + "Actual Total Time": 0.889, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3328.22, + "Total Cost": 3347.51, + "Plan Rows": 7716, + "Plan Width": 192, + "Actual Startup Time": 0.883, + "Actual Total Time": 0.886, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 101.89, + "Total Cost": 3070.8, + "Plan Rows": 7716, + "Plan Width": 192, + "Actual Startup Time": 0.31, + "Actual Total Time": 0.622, + "Actual Rows": 4499, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.004501+00'::timestamp with time zone, '791f3fe8-7c0d-4901-8f0f-e02c44a4c4b9'::uuid))", + "Rows Removed by Filter": 4501, + "Exact Heap Blocks": 244, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 99.97, + "Plan Rows": 9023, + "Plan Width": 0, + "Actual Startup Time": 0.091, + "Actual Total Time": 0.091, + "Actual Rows": 9000, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid)", + "Shared Hit Blocks": 10, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.065, + "Triggers": [], + "Execution Time": 0.924 + } + }, + { + "chat_size": 9000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.10787702000288846, + "successful_rps": 926.9814831492606, + "p50_ms": 1.013809999676596, + "p95_ms": 1.4137680000203545, + "p99_ms": 1.606690999778948, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3294.67, + "Total Cost": 3294.8, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.639, + "Actual Total Time": 0.644, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3294.67, + "Total Cost": 3311.47, + "Plan Rows": 6718, + "Plan Width": 192, + "Actual Startup Time": 0.639, + "Actual Total Time": 0.641, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 38, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 101.64, + "Total Cost": 3070.55, + "Plan Rows": 6718, + "Plan Width": 192, + "Actual Startup Time": 0.498, + "Actual Total Time": 0.565, + "Actual Rows": 899, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.008101+00'::timestamp with time zone, '932a9b1e-7e13-4a94-8ae0-27127a2b0d14'::uuid))", + "Rows Removed by Filter": 8101, + "Exact Heap Blocks": 244, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 254, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 99.97, + "Plan Rows": 9023, + "Plan Width": 0, + "Actual Startup Time": 0.089, + "Actual Total Time": 0.089, + "Actual Rows": 9000, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid)", + "Shared Hit Blocks": 10, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.069, + "Triggers": [], + "Execution Time": 0.677 + } + }, + { + "chat_size": 100, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03476310599944554, + "successful_rps": 2876.6129241039325, + "p50_ms": 0.3296269997008494, + "p95_ms": 0.40918600006989436, + "p99_ms": 0.4478549999475945, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 340.72, + "Total Cost": 340.85, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.03, + "Actual Total Time": 0.034, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 340.72, + "Total Cost": 340.96, + "Plan Rows": 97, + "Plan Width": 192, + "Actual Startup Time": 0.03, + "Actual Total Time": 0.031, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "quicksort", + "Sort Space Used": 47, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 5.04, + "Total Cost": 337.52, + "Plan Rows": 97, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.016, + "Actual Rows": 89, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.000011+00'::timestamp with time zone, 'd92d7f34-94d3-4621-b3ca-fae1968cdee8'::uuid))", + "Rows Removed by Filter": 11, + "Exact Heap Blocks": 4, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 5.02, + "Plan Rows": 97, + "Plan Width": 0, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.003, + "Actual Rows": 100, + "Actual Loops": 1, + "Index Cond": "(chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid)", + "Shared Hit Blocks": 2, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.067, + "Triggers": [], + "Execution Time": 0.061 + } + }, + { + "chat_size": 100, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.035047746999680385, + "successful_rps": 2853.250452901065, + "p50_ms": 0.32902200018725125, + "p95_ms": 0.4999630000384059, + "p99_ms": 0.5605359997389314, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 340.68, + "Total Cost": 340.81, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.027, + "Actual Total Time": 0.031, + "Actual Rows": 49, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 340.68, + "Total Cost": 340.92, + "Plan Rows": 96, + "Plan Width": 192, + "Actual Startup Time": 0.026, + "Actual Total Time": 0.028, + "Actual Rows": 49, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "quicksort", + "Sort Space Used": 37, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 5.04, + "Total Cost": 337.52, + "Plan Rows": 96, + "Plan Width": 192, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.018, + "Actual Rows": 49, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.000051+00'::timestamp with time zone, 'c9bebfa4-aab4-4e76-8aee-baadc67f5b62'::uuid))", + "Rows Removed by Filter": 51, + "Exact Heap Blocks": 4, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 5.02, + "Plan Rows": 97, + "Plan Width": 0, + "Actual Startup Time": 0.005, + "Actual Total Time": 0.005, + "Actual Rows": 100, + "Actual Loops": 1, + "Index Cond": "(chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid)", + "Shared Hit Blocks": 2, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.073, + "Triggers": [], + "Execution Time": 0.062 + } + }, + { + "chat_size": 100, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.016015682997476688, + "successful_rps": 6243.879828025771, + "p50_ms": 0.15205299996523536, + "p95_ms": 0.19920599970646435, + "p99_ms": 0.2571320001152344, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 340.68, + "Total Cost": 340.81, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.016, + "Actual Total Time": 0.017, + "Actual Rows": 9, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 340.68, + "Total Cost": 340.92, + "Plan Rows": 96, + "Plan Width": 192, + "Actual Startup Time": 0.016, + "Actual Total Time": 0.016, + "Actual Rows": 9, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "quicksort", + "Sort Space Used": 27, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Heap Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 5.04, + "Total Cost": 337.52, + "Plan Rows": 96, + "Plan Width": 192, + "Actual Startup Time": 0.013, + "Actual Total Time": 0.014, + "Actual Rows": 9, + "Actual Loops": 1, + "Recheck Cond": "(chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.000091+00'::timestamp with time zone, '08af9a4a-ba92-4773-b90c-48860e4e308a'::uuid))", + "Rows Removed by Filter": 91, + "Exact Heap Blocks": 4, + "Lossy Heap Blocks": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Bitmap Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Index Name": "research_idx", + "Startup Cost": 0.0, + "Total Cost": 5.02, + "Plan Rows": 97, + "Plan Width": 0, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.003, + "Actual Rows": 100, + "Actual Loops": 1, + "Index Cond": "(chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid)", + "Shared Hit Blocks": 2, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.064, + "Triggers": [], + "Execution Time": 0.044 + } + } + ] + }, + { + "name": "composite", + "ddl": "CREATE INDEX research_idx ON messages(chat_id,created_at,id)", + "build_seconds": 0.111595443999704, + "index_bytes": 6234112, + "write_1000_commit_seconds": [ + 0.04693998999982796, + 0.051292841999838856, + 0.0557781510001405 + ], + "write_median_rows_per_second": 19495.897692764647, + "cases": [ + { + "chat_size": 70000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.041383087997019175, + "successful_rps": 2416.4460614249715, + "p50_ms": 0.37220299964246806, + "p95_ms": 0.6553749999511638, + "p99_ms": 0.7813890001671098, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 13.25, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.011, + "Actual Total Time": 0.016, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 13764.94, + "Plan Rows": 54698, + "Plan Width": 192, + "Actual Startup Time": 0.011, + "Actual Total Time": 0.014, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.007001+00'::timestamp with time zone, '80faa22b-17f0-494e-8a8f-c9cf7b79c163'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.028, + "Triggers": [], + "Execution Time": 0.029 + } + }, + { + "chat_size": 70000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04392264599982809, + "successful_rps": 2276.7298673306564, + "p50_ms": 0.3974350001954008, + "p95_ms": 0.6794159999117255, + "p99_ms": 0.8419819996561273, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 26.11, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.013, + "Actual Total Time": 0.02, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 12263.78, + "Plan Rows": 24343, + "Plan Width": 192, + "Actual Startup Time": 0.013, + "Actual Total Time": 0.017, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.035001+00'::timestamp with time zone, '8c6bb688-4bf1-48bc-b8c4-d383944c3cb5'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.039, + "Triggers": [], + "Execution Time": 0.04 + } + }, + { + "chat_size": 70000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04076590000113356, + "successful_rps": 2453.030596582422, + "p50_ms": 0.3765860001294641, + "p95_ms": 0.5873780000911211, + "p99_ms": 0.6570290001945978, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 110.0, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.016, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 10512.22, + "Plan Rows": 4892, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.013, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.063001+00'::timestamp with time zone, '88938e51-1e25-4508-85e5-4c8e47fd3576'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.026, + "Triggers": [], + "Execution Time": 0.029 + } + }, + { + "chat_size": 20000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04665251200003695, + "successful_rps": 2143.507299240838, + "p50_ms": 0.42907299985017744, + "p95_ms": 0.6925920001776831, + "p99_ms": 1.1447839997345, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 33.34, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.017, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 11980.71, + "Plan Rows": 18561, + "Plan Width": 192, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.014, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.002001+00'::timestamp with time zone, '01bd6fea-2be5-403c-b230-bdfc889d5730'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.026, + "Triggers": [], + "Execution Time": 0.031 + } + }, + { + "chat_size": 20000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03875026900141165, + "successful_rps": 2580.627246648457, + "p50_ms": 0.35081500027445145, + "p95_ms": 0.5369510004129552, + "p99_ms": 0.7291689998965012, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 43.29, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.011, + "Actual Total Time": 0.016, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 11750.29, + "Plan Rows": 13977, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.014, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.010001+00'::timestamp with time zone, '758312ad-f300-4498-87fb-4f456e7d7d26'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.024, + "Triggers": [], + "Execution Time": 0.029 + } + }, + { + "chat_size": 20000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03709214699892982, + "successful_rps": 2695.9884528357225, + "p50_ms": 0.3494699999464501, + "p95_ms": 0.5027769998378062, + "p99_ms": 0.5548970002564602, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 55.25, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.012, + "Actual Total Time": 0.018, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 11592.47, + "Plan Rows": 10781, + "Plan Width": 192, + "Actual Startup Time": 0.012, + "Actual Total Time": 0.015, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.018001+00'::timestamp with time zone, 'f2cea50c-367f-4137-89b1-a168c16b4a7c'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.031, + "Triggers": [], + "Execution Time": 0.034 + } + }, + { + "chat_size": 9000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04408830999864222, + "successful_rps": 2268.174942588629, + "p50_ms": 0.4102230000171403, + "p95_ms": 0.647184000172274, + "p99_ms": 0.7235369998852548, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 68.41, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.018, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 7, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 11487.9, + "Plan Rows": 8617, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.015, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000901+00'::timestamp with time zone, '57960dbe-3131-4cde-b15a-c90d79b273d6'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 7, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.033, + "Triggers": [], + "Execution Time": 0.032 + } + }, + { + "chat_size": 9000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.037001367998072965, + "successful_rps": 2702.6027795839336, + "p50_ms": 0.34838300007322687, + "p95_ms": 0.500633000228845, + "p99_ms": 0.6056950001038786, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 76.57, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.016, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 11440.21, + "Plan Rows": 7661, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.013, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.004501+00'::timestamp with time zone, '791f3fe8-7c0d-4901-8f0f-e02c44a4c4b9'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.024, + "Triggers": [], + "Execution Time": 0.028 + } + }, + { + "chat_size": 9000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03956251300178337, + "successful_rps": 2527.645298858853, + "p50_ms": 0.34910400017906795, + "p95_ms": 0.6024100002832711, + "p99_ms": 0.6948939999347203, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 87.36, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.012, + "Actual Total Time": 0.017, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 11392.04, + "Plan Rows": 6682, + "Plan Width": 192, + "Actual Startup Time": 0.012, + "Actual Total Time": 0.015, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.008101+00'::timestamp with time zone, '932a9b1e-7e13-4a94-8ae0-27127a2b0d14'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.026, + "Triggers": [], + "Execution Time": 0.032 + } + }, + { + "chat_size": 100, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.037801948994456325, + "successful_rps": 2645.3662485673703, + "p50_ms": 0.3530710000632098, + "p95_ms": 0.49992200001724996, + "p99_ms": 0.6290189999162976, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 201.25, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.015, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 421.77, + "Plan Rows": 107, + "Plan Width": 192, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.012, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000011+00'::timestamp with time zone, 'd92d7f34-94d3-4621-b3ca-fae1968cdee8'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.023, + "Triggers": [], + "Execution Time": 0.028 + } + }, + { + "chat_size": 100, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.0364496759980284, + "successful_rps": 2743.508611857321, + "p50_ms": 0.3465549998509232, + "p95_ms": 0.48869500005821465, + "p99_ms": 0.5261889996290847, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 201.24, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.016, + "Actual Rows": 49, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 417.81, + "Plan Rows": 106, + "Plan Width": 192, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.013, + "Actual Rows": 49, + "Actual Loops": 1, + "Index Cond": "((chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000051+00'::timestamp with time zone, 'c9bebfa4-aab4-4e76-8aee-baadc67f5b62'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.024, + "Triggers": [], + "Execution Time": 0.028 + } + }, + { + "chat_size": 100, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.019799011999566574, + "successful_rps": 5050.757078292045, + "p50_ms": 0.17754400005287607, + "p95_ms": 0.29589299992949236, + "p99_ms": 0.36165500023344066, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 201.24, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.01, + "Actual Rows": 9, + "Actual Loops": 1, + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 417.81, + "Plan Rows": 106, + "Plan Width": 192, + "Actual Startup Time": 0.008, + "Actual Total Time": 0.009, + "Actual Rows": 9, + "Actual Loops": 1, + "Index Cond": "((chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000091+00'::timestamp with time zone, '08af9a4a-ba92-4773-b90c-48860e4e308a'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.022, + "Triggers": [], + "Execution Time": 0.023 + } + } + ] + }, + { + "name": "covering", + "ddl": "CREATE INDEX research_idx ON messages(chat_id,created_at,id) INCLUDE(sender_id,text)", + "build_seconds": 0.2411143950002952, + "index_bytes": 24576000, + "write_1000_commit_seconds": [ + 0.055284613000367244, + 0.056680701000004774, + 0.045771718000196415 + ], + "write_median_rows_per_second": 18088.215612422886, + "cases": [ + { + "chat_size": 70000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04957065999678889, + "successful_rps": 2017.3223436298376, + "p50_ms": 0.4653819996747188, + "p95_ms": 0.7443629997396783, + "p99_ms": 0.9964219998437329, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.43, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.026, + "Actual Total Time": 0.05, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 7517.52, + "Plan Rows": 54655, + "Plan Width": 192, + "Actual Startup Time": 0.025, + "Actual Total Time": 0.034, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.007001+00'::timestamp with time zone, '80faa22b-17f0-494e-8a8f-c9cf7b79c163'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.094, + "Triggers": [], + "Execution Time": 0.083 + } + }, + { + "chat_size": 70000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.049511427999732405, + "successful_rps": 2019.735726477945, + "p50_ms": 0.4206859998703294, + "p95_ms": 0.8181879998119257, + "p99_ms": 1.8737999998847954, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.43, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.018, + "Actual Total Time": 0.028, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 3408.0, + "Plan Rows": 24779, + "Plan Width": 192, + "Actual Startup Time": 0.018, + "Actual Total Time": 0.025, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.035001+00'::timestamp with time zone, '8c6bb688-4bf1-48bc-b8c4-d383944c3cb5'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.087, + "Triggers": [], + "Execution Time": 0.047 + } + }, + { + "chat_size": 70000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.09437181099701775, + "successful_rps": 1059.6384549954234, + "p50_ms": 0.5521519997273572, + "p95_ms": 1.0565100001258543, + "p99_ms": 1.5206779999061837, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.45, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.032, + "Actual Total Time": 0.046, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 683.46, + "Plan Rows": 4952, + "Plan Width": 192, + "Actual Startup Time": 0.032, + "Actual Total Time": 0.04, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'c9f802fd-c998-4180-9ca3-f02977eb8301'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.063001+00'::timestamp with time zone, '88938e51-1e25-4508-85e5-4c8e47fd3576'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.104, + "Triggers": [], + "Execution Time": 0.082 + } + }, + { + "chat_size": 20000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03786445699824981, + "successful_rps": 2640.9991830761564, + "p50_ms": 0.33988799987128004, + "p95_ms": 0.4876269999840588, + "p99_ms": 0.6899229997543443, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.44, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.02, + "Actual Total Time": 0.031, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 2560.3, + "Plan Rows": 18594, + "Plan Width": 192, + "Actual Startup Time": 0.02, + "Actual Total Time": 0.027, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.002001+00'::timestamp with time zone, '01bd6fea-2be5-403c-b230-bdfc889d5730'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.074, + "Triggers": [], + "Execution Time": 0.053 + } + }, + { + "chat_size": 20000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04774413200220806, + "successful_rps": 2094.4982305966987, + "p50_ms": 0.444366000010632, + "p95_ms": 0.6621190000259958, + "p99_ms": 1.2398469998515793, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.44, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.024, + "Actual Total Time": 0.032, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 1928.6, + "Plan Rows": 14009, + "Plan Width": 192, + "Actual Startup Time": 0.024, + "Actual Total Time": 0.029, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.010001+00'::timestamp with time zone, '758312ad-f300-4498-87fb-4f456e7d7d26'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.073, + "Triggers": [], + "Execution Time": 0.056 + } + }, + { + "chat_size": 20000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.05102691599904574, + "successful_rps": 1959.7500268656274, + "p50_ms": 0.4555680002340523, + "p95_ms": 0.8052859998315398, + "p99_ms": 1.440876999822649, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.45, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.021, + "Actual Total Time": 0.028, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 1492.98, + "Plan Rows": 10828, + "Plan Width": 192, + "Actual Startup Time": 0.02, + "Actual Total Time": 0.025, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '43c99015-4e1d-46c4-8a29-369516c20985'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.018001+00'::timestamp with time zone, 'f2cea50c-367f-4137-89b1-a168c16b4a7c'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.076, + "Triggers": [], + "Execution Time": 0.049 + } + }, + { + "chat_size": 9000, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.04266578400165599, + "successful_rps": 2343.7984872402367, + "p50_ms": 0.39160400001492235, + "p95_ms": 0.5713150003430201, + "p99_ms": 0.7498550003219862, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.43, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.016, + "Actual Total Time": 0.027, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 1179.92, + "Plan Rows": 8575, + "Plan Width": 192, + "Actual Startup Time": 0.016, + "Actual Total Time": 0.024, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000901+00'::timestamp with time zone, '57960dbe-3131-4cde-b15a-c90d79b273d6'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.071, + "Triggers": [], + "Execution Time": 0.044 + } + }, + { + "chat_size": 9000, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.0400733649967151, + "successful_rps": 2495.423082344026, + "p50_ms": 0.38468799994006986, + "p95_ms": 0.4954159999215335, + "p99_ms": 0.560278000193648, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.44, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.013, + "Actual Total Time": 0.022, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 1048.7, + "Plan Rows": 7614, + "Plan Width": 192, + "Actual Startup Time": 0.012, + "Actual Total Time": 0.019, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.004501+00'::timestamp with time zone, '791f3fe8-7c0d-4901-8f0f-e02c44a4c4b9'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 6, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.069, + "Triggers": [], + "Execution Time": 0.039 + } + }, + { + "chat_size": 9000, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.040342096999665955, + "successful_rps": 2478.800246819793, + "p50_ms": 0.3790359996855841, + "p95_ms": 0.5729120002797572, + "p99_ms": 0.6265740003073006, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 7.46, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.018, + "Actual Total Time": 0.024, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 917.26, + "Plan Rows": 6642, + "Plan Width": 192, + "Actual Startup Time": 0.017, + "Actual Total Time": 0.021, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'ee38cff2-be26-4a0d-97b7-9d4102096aba'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.008101+00'::timestamp with time zone, '932a9b1e-7e13-4a94-8ae0-27127a2b0d14'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.07, + "Triggers": [], + "Execution Time": 0.046 + } + }, + { + "chat_size": 100, + "depth": 0.1, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03870596699971429, + "successful_rps": 2583.5809760479087, + "p50_ms": 0.3660150000541762, + "p95_ms": 0.5082419997961551, + "p99_ms": 0.6601979998777097, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 9.09, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.014, + "Actual Total Time": 0.023, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 14.02, + "Plan Rows": 80, + "Plan Width": 192, + "Actual Startup Time": 0.014, + "Actual Total Time": 0.019, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000011+00'::timestamp with time zone, 'd92d7f34-94d3-4621-b3ca-fae1968cdee8'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.077, + "Triggers": [], + "Execution Time": 0.039 + } + }, + { + "chat_size": 100, + "depth": 0.5, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.03887745500060191, + "successful_rps": 2572.1848304744167, + "p50_ms": 0.34716100026344066, + "p95_ms": 0.6183809996400669, + "p99_ms": 1.0694019997572468, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 9.09, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.022, + "Actual Total Time": 0.03, + "Actual Rows": 49, + "Actual Loops": 1, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 14.02, + "Plan Rows": 80, + "Plan Width": 192, + "Actual Startup Time": 0.022, + "Actual Total Time": 0.027, + "Actual Rows": 49, + "Actual Loops": 1, + "Index Cond": "((chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000051+00'::timestamp with time zone, 'c9bebfa4-aab4-4e76-8aee-baadc67f5b62'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 5, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.076, + "Triggers": [], + "Execution Time": 0.053 + } + }, + { + "chat_size": 100, + "depth": 0.9, + "successful_queries": 100, + "errors": 0, + "duration_seconds": 0.021500679995824612, + "successful_rps": 4651.015689709339, + "p50_ms": 0.18678600008570356, + "p95_ms": 0.3326729997752409, + "p99_ms": 0.3666259999590693, + "plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.42, + "Total Cost": 9.18, + "Plan Rows": 51, + "Plan Width": 192, + "Actual Startup Time": 0.013, + "Actual Total Time": 0.015, + "Actual Rows": 9, + "Actual Loops": 1, + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Only Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "research_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.42, + "Total Cost": 14.0, + "Plan Rows": 79, + "Plan Width": 192, + "Actual Startup Time": 0.013, + "Actual Total Time": 0.014, + "Actual Rows": 9, + "Actual Loops": 1, + "Index Cond": "((chat_id = '44747c11-d90a-436f-9ec0-a01325912444'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.000091+00'::timestamp with time zone, '08af9a4a-ba92-4773-b90c-48860e4e308a'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Heap Fetches": 0, + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.069, + "Triggers": [], + "Execution Time": 0.033 + } + } + ] + } + ], + "query": "SELECT * FROM messages WHERE chat_id=%s AND (created_at,id)>(%s,%s) ORDER BY created_at,id LIMIT 51", + "final_count": 100000, + "total_research_seconds": 14.285892900021281, + "resources": [ + { + "elapsed_seconds": 1.977, + "docker": { + "BlockIO": "7.45MB / 70.1MB", + "CPUPerc": "92.69%", + "Container": "92075e2bbf03ab04a43dccc4b171554af2781687127bd343453182cdcf3fb0ec", + "ID": "92075e2bbf03", + "MemPerc": "13.54%", + "MemUsage": "69.31MiB / 512MiB", + "Name": "lyakhonov-lab2-db-1", + "NetIO": "46.3kB / 42.8kB", + "PIDs": "8" + } + }, + { + "elapsed_seconds": 4.988, + "docker": { + "BlockIO": "7.45MB / 95.5MB", + "CPUPerc": "98.84%", + "Container": "92075e2bbf03ab04a43dccc4b171554af2781687127bd343453182cdcf3fb0ec", + "ID": "92075e2bbf03", + "MemPerc": "14.39%", + "MemUsage": "73.66MiB / 512MiB", + "Name": "lyakhonov-lab2-db-1", + "NetIO": "47.7kB / 43.7kB", + "PIDs": "8" + } + }, + { + "elapsed_seconds": 7.971, + "docker": { + "BlockIO": "7.45MB / 103MB", + "CPUPerc": "93.61%", + "Container": "92075e2bbf03ab04a43dccc4b171554af2781687127bd343453182cdcf3fb0ec", + "ID": "92075e2bbf03", + "MemPerc": "14.79%", + "MemUsage": "75.74MiB / 512MiB", + "Name": "lyakhonov-lab2-db-1", + "NetIO": "95.2kB / 1.9MB", + "PIDs": "8" + } + }, + { + "elapsed_seconds": 10.965, + "docker": { + "BlockIO": "7.45MB / 104MB", + "CPUPerc": "82.17%", + "Container": "92075e2bbf03ab04a43dccc4b171554af2781687127bd343453182cdcf3fb0ec", + "ID": "92075e2bbf03", + "MemPerc": "16.60%", + "MemUsage": "85MiB / 512MiB", + "Name": "lyakhonov-lab2-db-1", + "NetIO": "433kB / 17.8MB", + "PIDs": "9" + } + }, + { + "elapsed_seconds": 14.286, + "docker": { + "BlockIO": "7.45MB / 278MB", + "CPUPerc": "16.80%", + "Container": "92075e2bbf03ab04a43dccc4b171554af2781687127bd343453182cdcf3fb0ec", + "ID": "92075e2bbf03", + "MemPerc": "17.34%", + "MemUsage": "88.77MiB / 512MiB", + "Name": "lyakhonov-lab2-db-1", + "NetIO": "1.22MB / 53.2MB", + "PIDs": "7" + } + } + ], + "postgres_version": "postgres (PostgreSQL) 16.6" +} diff --git a/infra/extensions.md b/infra/extensions.md new file mode 100644 index 00000000..24781299 --- /dev/null +++ b/infra/extensions.md @@ -0,0 +1,3 @@ +# Дополнительная диагностика + +`GET /stats` — необязательное расширение API: числа users/chats/messages и счётчики profile_cache.hits/misses/errors/ttl_seconds. Счётчики кэша живут в процессе и сбрасываются при его перезапуске. Ответ не раскрывает профили, тексты, хеши паролей или токены. Публичный обязательный контракт не изменён. Ограничитель количества запросов сохранён из lab1: не более 100 одновременно обслуживаемых запросов в одном процессе; переполнение — 503 unavailable. Это не распределённый rate limiter. diff --git a/scripts/research.py b/scripts/research.py new file mode 100644 index 00000000..04633e87 --- /dev/null +++ b/scripts/research.py @@ -0,0 +1,107 @@ +"""Повторяемое исследование SQL, сбор CPU/RAM, backup и восстановление в новый том.""" +import json +import os +from pathlib import Path +import subprocess +import threading +import time +import uuid + +ROOT=Path(__file__).resolve().parents[1] +os.chdir(ROOT) + + +def command(args): + result=subprocess.run(args,capture_output=True,text=True,encoding='utf-8',errors='replace',check=True) + return result.stdout.strip() + + +def compose(*args): + return command(['docker','compose',*args]) + + +def database_query(service,database,query): + output=compose('exec','-T',service,'psql','-U','messenger','-d',database,'-Atc',query) + return json.loads(output) + + +def main(): + evidence=ROOT/'evidence' + evidence.mkdir(exist_ok=True) + stats=[] + stop=threading.Event() + def collect(): + while not stop.is_set(): + raw=command(['docker','stats','--no-stream','--format','{{json .}}',compose('ps','-q','db')]) + stats.append({'elapsed_seconds':round(time.monotonic()-started,3),'docker':json.loads(raw)}) + stop.wait(1) + started=time.monotonic() + collector=threading.Thread(target=collect) + collector.start() + try: + source=(ROOT/'student-tests/research_worker.py').read_text(encoding='utf-8') + proc=subprocess.run(['docker','compose','exec','-T','api','python','-'],input=source,capture_output=True,text=True,encoding='utf-8',check=True) + result=json.loads(proc.stdout) + finally: + stop.set() + collector.join() + result['total_research_seconds']=time.monotonic()-started + result['resources']=stats + result['postgres_version']=compose('exec','-T','db','postgres','--version') + (evidence/'research.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') + print('SQL-исследование завершено: 100 000 сообщений, три индекса.') + # Дамп содержит синтетические данные; бинарный архив остаётся вне Git. + folder=ROOT/'backups' + folder.mkdir(exist_ok=True) + archive='research_'+uuid.uuid4().hex[:10]+'.dump' + before=time.perf_counter() + compose('exec','-T','db','pg_dump','-U','messenger','-d',result['database'],'-Fc','-f','/tmp/'+archive) + db_id=compose('ps','-q','db') + command(['docker','cp',db_id+':/tmp/'+archive,str(folder/archive)]) + backup_seconds=time.perf_counter()-before + # Каждый запуск получает новый отдельный том; существующие тома не удаляются. + restore_volume='lyakhonov_lab2_restore_'+uuid.uuid4().hex[:10] + restore_name=restore_volume.replace('_','-') + command(['docker','volume','create',restore_volume]) + before=time.perf_counter() + password_file=str(ROOT/'secrets/db_password') + command(['docker','run','-d','--name',restore_name,'--network','lyakhonov-lab2_default', + '--cpus','1','--memory','512m','-e','POSTGRES_USER=messenger','-e','POSTGRES_DB=messenger', + '-e','POSTGRES_PASSWORD_FILE=/run/secrets/db_password','--mount','type=bind,src='+password_file+',dst=/run/secrets/db_password,readonly', + '-v',restore_volume+':/var/lib/postgresql/data','postgres:16.6-alpine']) + deadline=time.monotonic()+60 + while True: + ready=subprocess.run(['docker','exec',restore_name,'pg_isready','-h','127.0.0.1','-U','messenger','-d','messenger'],capture_output=True) + if ready.returncode==0: + break + if time.monotonic()>deadline: + raise RuntimeError('новое хранилище не готово') + time.sleep(0.5) + command(['docker','cp',str(folder/archive),restore_name+':/tmp/'+archive]) + restore_start=time.perf_counter() + command(['docker','exec',restore_name,'pg_restore','-U','messenger','-d','messenger','--exit-on-error','--no-owner','/tmp/'+archive]) + restore_seconds=time.perf_counter()-restore_start + provision_restore_seconds=time.perf_counter()-before + counts="SELECT json_build_object('users',(SELECT count(*) FROM users),'chats',(SELECT count(*) FROM chats),'members',(SELECT count(*) FROM chat_members),'messages',(SELECT count(*) FROM messages),'sessions',(SELECT count(*) FROM sessions))" + fingerprint="SELECT json_build_object('count',count(*),'digest',md5(string_agg(md5(id::text || chat_id::text || sender_id::text || text || created_at::text),'' ORDER BY id))) FROM messages" + samples="SELECT json_agg(t ORDER BY chat_id,id) FROM (SELECT * FROM (SELECT id,chat_id,sender_id,text,created_at,row_number() OVER(PARTITION BY chat_id ORDER BY created_at,id) AS n,count(*) OVER(PARTITION BY chat_id) AS total FROM messages) s WHERE n=1 OR n=total OR n=total/2) t" + def restored(query): + return json.loads(command(['docker','exec',restore_name,'psql','-U','messenger','-d','messenger','-Atc',query])) + checks={} + for label,query in [('counts',counts),('all_message_fingerprint',fingerprint),('selected_messages',samples)]: + original=database_query('db',result['database'],query) + recovered=restored(query) + assert original==recovered, 'расхождение после восстановления: '+label + checks[label]={'equal':True,'value':original} + recovery={'source_database':result['database'],'restore_container':restore_name,'new_volume':restore_volume, + 'archive_file':'backups/'+archive,'archive_bytes':(folder/archive).stat().st_size, + 'backup_seconds':backup_seconds,'restore_seconds':restore_seconds,'provision_and_restore_seconds':provision_restore_seconds, + 'checks':checks,'snapshot_message_loss':0,'passed':True} + (evidence/'recovery.json').write_text(json.dumps(recovery,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') + print('PASS: backup восстановлен в новый том; количество, все сообщения и выборка совпали.') + # Контейнер исследования останавливается; том сохраняется для защиты. + command(['docker','stop',restore_name]) + + +if __name__=='__main__': + main() diff --git a/student-tests/README.md b/student-tests/README.md index 265b2559..8bf5d50a 100644 --- a/student-tests/README.md +++ b/student-tests/README.md @@ -1,2 +1,10 @@ # Собственные проверки лабораторной 2 -Исходные test_lab1.py, test_degradation.py и metrics_collector.py перенесены как история реализации lab1 и не являются проверками lab2: в них используется X-User-Id. Актуальные проверки lab2 описаны в REPORT.md. + +- `python student-tests/test_lab2.py` — валидация, доступ, курсоры, 100 сообщений от 10 клиентов. +- `python student-tests/test_level4.py` — гонка регистрации, rollback, Redis, отказ БД, expiry и logout. Временно останавливает только сервисы этого учебного Compose-проекта; основной API должен быть на 8080, порт 8082 свободен. +- `python student-tests/explain_level4.py` — добавляет 10 000 синтетических сообщений и сохраняет SQL-план. +- `python scripts/research.py` — создаёт отдельную исследовательскую БД на 100 000 сообщений, сравнивает три индекса, сохраняет дамп вне Git и восстанавливает его в новый отдельный Docker-том. Исследовательский контейнер после сверки остановлен, том и БД сохранены для защиты. Каждый повтор создаёт новые ресурсы; список записан в evidence/research.json и evidence/recovery.json. + +Все команды запускаются из корня репозитория. Требуются работающий Docker Desktop в режиме Linux containers и Python 3.9+ на машине запуска. Сами публичные проверки используют только стандартную библиотеку Python; зависимости приложения устанавливаются внутри образа. + +Старые тесты lab1 с X-User-Id и эксперимент token bucket заменены актуальными проверками lab2. Публичные tests/ и обязательный contracts/ сохранены. diff --git a/student-tests/metrics_collector.py b/student-tests/metrics_collector.py deleted file mode 100644 index 085b1164..00000000 --- a/student-tests/metrics_collector.py +++ /dev/null @@ -1,217 +0,0 @@ -#!/usr/bin/env python3 -"""Сбор метрик деградации и автоматическая генерация графиков. - -Запуск: - # 1. Запустить сервер с лимитами (в отдельном терминале): - export MAX_USERS=100 MAX_CHATS=100 MAX_MESSAGES=1000 MAX_MESSAGES_PER_CHAT=100 MAX_REQUEST_QUEUE=50 MAX_MESSAGES_PER_SECOND=5 - python -m uvicorn src.app:app --host 0.0.0.0 --port 8081 - - # 2. Запустить сборщик: - python student-tests/metrics_collector.py - - # 3. CSV и графики появятся в папке metrics/ -""" -import csv -import json -import os -import threading -import time -import urllib.request -import uuid - -# matplotlib для построения графиков -import matplotlib -matplotlib.use("Agg") # неинтерактивный бэкенд (без GUI) -import matplotlib.pyplot as plt - -BASE_URL = "http://localhost:8081" -METRICS_DIR = "metrics" -CSV_FILE = os.path.join(METRICS_DIR, "metrics_data.csv") -DURATION_SECONDS = 15 -BURST_INTERVAL = 0.05 # отправлять сообщение каждые 50 мс = 20/сек - - -def request(method, path, body=None, headers=None): - h = {"Accept": "application/json"} - if body is not None: - raw = json.dumps(body, ensure_ascii=False).encode("utf-8") - h["Content-Type"] = "application/json" - else: - raw = None - h.update(headers or {}) - req = urllib.request.Request(BASE_URL + path, data=raw, headers=h, method=method) - try: - resp = urllib.request.urlopen(req) - return json.loads(resp.read().decode()) if resp.read else None - except urllib.error.HTTPError as e: - return {"error": {"code": e.code}} - - -def get_stats(): - """Получить текущую статистику с сервера.""" - req = urllib.request.Request(BASE_URL + "/stats", method="GET") - try: - resp = urllib.request.urlopen(req) - return json.loads(resp.read().decode()) - except Exception: - return None - - -def ensure_dir(path): - """Создать папку, если её нет.""" - os.makedirs(path, exist_ok=True) - - -def plot_metrics(metrics_log): - """Построить графики по собранным метрикам и сохранить в metrics/.""" - ensure_dir(METRICS_DIR) - - times = [m["time"] for m in metrics_log] - # Нормализуем время: начало = 0 - t0 = times[0] if times else 0 - times_norm = [t - t0 for t in times] - - total_attempts = [m["total_attempts"] for m in metrics_log] - rate_limited = [m["rate_limited"] for m in metrics_log] - available_tokens = [m["available_tokens"] for m in metrics_log] - messages = [m["messages"] for m in metrics_log] - - # График 1: Нагрузка и ошибки - fig, ax1 = plt.subplots(figsize=(10, 5)) - ax1.set_xlabel("Время, сек") - ax1.set_ylabel("Количество") - ax1.plot(times_norm, total_attempts, "b-", label="Всего попыток", linewidth=2) - ax1.plot(times_norm, rate_limited, "r-", label="Отклонено (429)", linewidth=2) - ax1.plot(times_norm, messages, "g-", label="Создано сообщений", linewidth=2) - ax1.legend(loc="upper left") - ax1.grid(True, alpha=0.3) - ax1.set_title("Нагрузка и ошибки при rate limiting") - plt.tight_layout() - path1 = os.path.join(METRICS_DIR, "load_and_errors.png") - fig.savefig(path1, dpi=150) - plt.close(fig) - print(f" Сохранён: {path1}") - - # График 2: Токены bucket - fig, ax = plt.subplots(figsize=(10, 5)) - ax.set_xlabel("Время, сек") - ax.set_ylabel("Доступные токены") - ax.fill_between(times_norm, available_tokens, alpha=0.4, color="orange") - ax.plot(times_norm, available_tokens, "orange", linewidth=2, label="Токены в bucket") - ax.axhline(y=5, color="gray", linestyle="--", alpha=0.5, label="MAX_MESSAGES_PER_SECOND=5") - ax.legend() - ax.grid(True, alpha=0.3) - ax.set_title("Состояние token bucket") - plt.tight_layout() - path2 = os.path.join(METRICS_DIR, "tokens.png") - fig.savefig(path2, dpi=150) - plt.close(fig) - print(f" Сохранён: {path2}") - - # График 3: Соотношение успех/отказ (кумулятивное) - fig, ax = plt.subplots(figsize=(10, 5)) - success = [total_attempts[i] - rate_limited[i] for i in range(len(total_attempts))] - ax.set_xlabel("Время, сек") - ax.set_ylabel("Количество") - ax.stackplot( - times_norm, - success, - rate_limited, - labels=["Успешно", "Отклонено (429)"], - colors=["#2ecc71", "#e74c3c"], - alpha=0.8, - ) - ax.legend(loc="upper left") - ax.grid(True, alpha=0.3) - ax.set_title("Успешные запросы vs отказы (кумулятивно)") - plt.tight_layout() - path3 = os.path.join(METRICS_DIR, "success_vs_rejected.png") - fig.savefig(path3, dpi=150) - plt.close(fig) - print(f" Сохранён: {path3}") - - return path1, path2, path3 - - -def main(): - print("=== Сбор метрик деградации и генерация графиков ===") - print(f"Результат: папка {METRICS_DIR}/") - print(f"Длительность: {DURATION_SECONDS} секунд") - print() - - # Создаём пользователей и чат - alice = request("POST", "/api/v1/users", body={"username": "metrics_alice_" + uuid.uuid4().hex[:6], "display_name": "Alice"}) - bob = request("POST", "/api/v1/users", body={"username": "metrics_bob_" + uuid.uuid4().hex[:6], "display_name": "Bob"}) - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Metrics", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - ) - chat_id = chat["id"] - - # Поток для сбора метрик - metrics_log = [] - stop_event = threading.Event() - - def collector(): - while not stop_event.is_set(): - stats = get_stats() - if stats: - metrics_log.append({ - "time": round(time.time(), 2), - "total_attempts": stats.get("metrics", {}).get("total_message_attempts", 0), - "rate_limited": stats.get("metrics", {}).get("rate_limited_count", 0), - "available_tokens": stats.get("rate_limit", {}).get("available_tokens", 0), - "messages": stats.get("messages", 0), - "requests_in_flight": stats.get("requests_in_flight", 0), - }) - time.sleep(0.1) - - collector_thread = threading.Thread(target=collector) - collector_thread.start() - - # Нагрузка: отправляем сообщения быстрее лимита - print("Начинаем нагрузку...") - start = time.time() - msg_count = 0 - while time.time() - start < DURATION_SECONDS: - request( - "POST", - f"/api/v1/chats/{chat_id}/messages", - body={"text": f"msg{msg_count}"}, - headers={"X-User-Id": alice["id"]}, - ) - msg_count += 1 - time.sleep(BURST_INTERVAL) - - print(f"Отправлено {msg_count} сообщений. Ждём завершения сбора...") - time.sleep(2) # даём время собрать метрики после нагрузки - stop_event.set() - collector_thread.join() - - # Сохраняем CSV - ensure_dir(METRICS_DIR) - with open(CSV_FILE, "w", newline="", encoding="utf-8") as f: - writer = csv.DictWriter(f, fieldnames=[ - "time", "total_attempts", "rate_limited", "available_tokens", - "messages", "requests_in_flight", - ]) - writer.writeheader() - writer.writerows(metrics_log) - - print(f"\nСохранено {len(metrics_log)} записей в {CSV_FILE}") - - # Строим графики - print("\nСтроим графики...") - paths = plot_metrics(metrics_log) - - print("\n=== ГОТОВО ===") - print(f"Папка с графиками: {METRICS_DIR}/") - for p in paths: - print(f" - {p}") - print("\nЭти файлы можно вставить в REPORT.md как доказательства работы rate limiting.") - - -if __name__ == "__main__": - main() diff --git a/student-tests/research_worker.py b/student-tests/research_worker.py new file mode 100644 index 00000000..c89f1ba0 --- /dev/null +++ b/student-tests/research_worker.py @@ -0,0 +1,92 @@ +"""Сравнение индексов в отдельной БД, не затрагивающее данные API.""" +import json +from pathlib import Path +import statistics +import time +import uuid +import psycopg +from psycopg import sql +from psycopg.conninfo import make_conninfo +from psycopg.rows import dict_row +from src.config import setting + + +def percentile(values, p): + ordered=sorted(values) + return ordered[min(len(ordered)-1, int((len(ordered)-1)*p))] + + +def main(): + name='lab2_research_'+uuid.uuid4().hex[:10] + url=setting('DATABASE_URL') + with psycopg.connect(url,autocommit=True) as admin: + admin.execute(sql.SQL('CREATE DATABASE {}').format(sql.Identifier(name))) + conn=psycopg.connect(make_conninfo(url,dbname=name),row_factory=dict_row,autocommit=True) + conn.execute("SET statement_timeout='30s'") + for path in sorted(Path('/app/migrations').glob('*.sql')): + conn.execute(path.read_text(encoding='utf-8')) + user=str(uuid.uuid4()) + conn.execute("INSERT INTO users(id,username,display_name,password_hash) VALUES (%s,'research','Синтетический пользователь','не используется для входа')",[user]) + sizes=[70000,20000,9000]+[100]*10 + chats=[] + seed_started=time.perf_counter() + with conn.transaction(): + for i,size in enumerate(sizes): + chat=str(uuid.uuid4()) + chats.append(chat) + conn.execute('INSERT INTO chats(id,title) VALUES (%s,%s)',[chat,'Исследование '+str(i)]) + conn.execute('INSERT INTO chat_members VALUES (%s,%s)',[chat,user]) + conn.execute("INSERT INTO messages(id,chat_id,sender_id,text,created_at) SELECT gen_random_uuid(),%s,%s,repeat('x',128) || n, timestamptz '2026-01-01' + n * interval '1 microsecond' FROM generate_series(1,%s) n",[chat,user,size]) + seed_seconds=time.perf_counter()-seed_started + conn.execute('DROP INDEX messages_history_idx') + conn.execute('VACUUM ANALYZE messages') + variants=[('chat_only','CREATE INDEX research_idx ON messages(chat_id)'), + ('composite','CREATE INDEX research_idx ON messages(chat_id,created_at,id)'), + ('covering','CREATE INDEX research_idx ON messages(chat_id,created_at,id) INCLUDE(sender_id,text)')] + result={'database':name,'rows':sum(sizes),'chat_sizes':sizes,'seed_seconds':seed_seconds, + 'concurrency':1,'warmup_queries_per_case':3,'queries_per_case':100,'repeats_write':3,'variants':[]} + query='SELECT * FROM messages WHERE chat_id=%s AND (created_at,id)>(%s,%s) ORDER BY created_at,id LIMIT 51' + result['query']=query + for label,ddl in variants: + started=time.perf_counter() + conn.execute(ddl) + build_seconds=time.perf_counter()-started + conn.execute('VACUUM ANALYZE messages') + cases=[] + for chat,size in zip(chats[:4],sizes[:4]): + for depth in [0.1,0.5,0.9]: + # OFFSET нужен только для выбора фиксированной точки эксперимента. + marker=conn.execute('SELECT created_at,id FROM messages WHERE chat_id=%s ORDER BY created_at,id OFFSET %s LIMIT 1',[chat,int(size*depth)]).fetchone() + params=[chat,marker['created_at'],marker['id']] + for _ in range(3): + conn.execute(query,params).fetchall() + timings=[] + for _ in range(100): + start=time.perf_counter() + rows=conn.execute(query,params).fetchall() + timings.append((time.perf_counter()-start)*1000) + assert len(rows)==min(51,size-int(size*depth)-1) + plan=conn.execute('EXPLAIN (ANALYZE,BUFFERS,FORMAT JSON) '+query,params).fetchone()['QUERY PLAN'][0] + cases.append({'chat_size':size,'depth':depth,'successful_queries':100,'errors':0, + 'duration_seconds':sum(timings)/1000,'successful_rps':100000/sum(timings), + 'p50_ms':percentile(timings,0.5),'p95_ms':percentile(timings,0.95),'p99_ms':percentile(timings,0.99),'plan':plan}) + writes=[] + for trial in range(3): + start=time.perf_counter() + with conn.transaction(): + conn.execute("INSERT INTO messages(id,chat_id,sender_id,text) SELECT gen_random_uuid(),%s,%s,'write_probe' FROM generate_series(1,1000)",[chats[0],user]) + writes.append(time.perf_counter()-start) + conn.execute("DELETE FROM messages WHERE text='write_probe'") + index_bytes=conn.execute("SELECT pg_relation_size('research_idx') AS n").fetchone()['n'] + result['variants'].append({'name':label,'ddl':ddl,'build_seconds':build_seconds,'index_bytes':index_bytes, + 'write_1000_commit_seconds':writes,'write_median_rows_per_second':1000/statistics.median(writes),'cases':cases}) + conn.execute('DROP INDEX research_idx') + conn.execute('CREATE INDEX messages_history_idx ON messages(chat_id,created_at,id)') + conn.execute('VACUUM ANALYZE messages') + result['final_count']=conn.execute('SELECT count(*) AS n FROM messages').fetchone()['n'] + assert result['final_count']==100000 + conn.close() + print(json.dumps(result,ensure_ascii=False,default=str)) + + +main() diff --git a/student-tests/test_degradation.py b/student-tests/test_degradation.py deleted file mode 100644 index 8783a312..00000000 --- a/student-tests/test_degradation.py +++ /dev/null @@ -1,244 +0,0 @@ -#!/usr/bin/env python3 -"""Тесты трека 2: управляемая деградация — лимиты и восстановление. - -Запуск: - # В одном терминале запустите сервер с агрессивными лимитами: - $env:MAX_USERS="10"; $env:MAX_CHATS="10"; $env:MAX_MESSAGES="50"; $env:MAX_MESSAGES_PER_CHAT="5"; $env:MAX_REQUEST_QUEUE="10"; $env:MAX_MESSAGES_PER_SECOND="10"; .venv\Scripts\python -m uvicorn src.app:app --host 0.0.0.0 --port 8081 - ИЛИ - export MAX_USERS=10 - export MAX_CHATS=10 - export MAX_MESSAGES=50 - export MAX_MESSAGES_PER_CHAT=5 - export MAX_REQUEST_QUEUE=10 - export MAX_MESSAGES_PER_SECOND=10 - python -m uvicorn src.app:app --host 0.0.0.0 --port 8081 - # В другом терминале: - .venv\Scripts\python student-tests/test_degradation.py -""" -import json -import urllib.error -import urllib.request -import uuid - -BASE_URL = "http://localhost:8081" - - -def request(method, path, body=None, headers=None, expected=200): - """Выполнить HTTP-запрос и проверить статус ответа.""" - h = {"Accept": "application/json"} - if body is not None: - raw = json.dumps(body, ensure_ascii=False).encode("utf-8") - h["Content-Type"] = "application/json" - else: - raw = None - h.update(headers or {}) - req = urllib.request.Request(BASE_URL + path, data=raw, headers=h, method=method) - try: - resp = urllib.request.urlopen(req) - except urllib.error.HTTPError as e: - resp = e - if resp.code != expected: - data = resp.read().decode() - raise AssertionError( - f"{method} {path}: ожидался {expected}, получен {resp.code}: {data}" - ) - data = resp.read() - return json.loads(data.decode()) if data else None - - -def test_user_limit(): - """При превышении MAX_USERS сервер возвращает 429.""" - # Создаём пользователей до лимита (некоторые уже созданы в main) - for i in range(8): - request( - "POST", - "/api/v1/users", - body={"username": f"u_limit_{i}_" + uuid.uuid4().hex[:8], "display_name": f"User{i}"}, - expected=201, - ) - - # Следующий пользователь должен получить 429 - req = urllib.request.Request( - BASE_URL + "/api/v1/users", - data=json.dumps({"username": "u_limit_extra_" + uuid.uuid4().hex[:8], "display_name": "Extra"}).encode(), - headers={"Content-Type": "application/json"}, - method="POST", - ) - try: - urllib.request.urlopen(req) - raise AssertionError("ожидалась ошибка 429") - except urllib.error.HTTPError as e: - assert e.code == 429, f"ожидался 429, получен {e.code}" - data = json.loads(e.read().decode()) - assert data["error"]["code"] == "rate_limited" - print("PASS: user_limit (429 при превышении MAX_USERS)") - - -def test_message_limit_per_chat(alice, bob): - """При превышении MAX_MESSAGES_PER_CHAT сервер возвращает 429.""" - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Limited", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - # Отправляем сообщения до лимита - for i in range(5): - request( - "POST", - f"/api/v1/chats/{chat['id']}/messages", - body={"text": f"msg{i}"}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - # Следующее сообщение должно получить 429 - req = urllib.request.Request( - BASE_URL + f"/api/v1/chats/{chat['id']}/messages", - data=json.dumps({"text": "overflow"}).encode(), - headers={"Content-Type": "application/json", "X-User-Id": alice["id"]}, - method="POST", - ) - try: - urllib.request.urlopen(req) - raise AssertionError("ожидалась ошибка 429") - except urllib.error.HTTPError as e: - assert e.code == 429, f"ожидался 429, получен {e.code}" - data = json.loads(e.read().decode()) - assert data["error"]["code"] == "rate_limited" - print("PASS: message_limit_per_chat (429 при превышении лимита сообщений)") - - -def test_recovery_after_load(alice, bob): - """После снятия нагрузки сервер восстанавливается и принимает новые запросы.""" - import time - - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Recovery", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - # Заполняем чат до лимита - for i in range(5): - request( - "POST", - f"/api/v1/chats/{chat['id']}/messages", - body={"text": f"msg{i}"}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - # Проверяем отказ (лимит чата) - req = urllib.request.Request( - BASE_URL + f"/api/v1/chats/{chat['id']}/messages", - data=json.dumps({"text": "overflow"}).encode(), - headers={"Content-Type": "application/json", "X-User-Id": alice["id"]}, - method="POST", - ) - try: - urllib.request.urlopen(req) - raise AssertionError("ожидалась ошибка 429") - except urllib.error.HTTPError as e: - assert e.code == 429 - - # Пауза: даём bucket'у rate limit пополниться - time.sleep(1.5) - - # Создаём новый чат — в нём лимит сообщений не исчерпан - chat2 = request( - "POST", - "/api/v1/chats", - body={"title": "Recovery2", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - # Новый запрос проходит — сервер восстановился - request( - "POST", - f"/api/v1/chats/{chat2['id']}/messages", - body={"text": "after load"}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - print("PASS: recovery_after_load (сервер восстанавливается после снятия нагрузки)") - - -def test_rate_limit(alice, bob): - """При превышении MAX_MESSAGES_PER_SECOND сервер возвращает 429, - а после паузы снова принимает сообщения.""" - import time - - # Создаём несколько чатов, чтобы не упираться в лимит сообщений на чат - chats = [] - for c in range(4): - chat = request( - "POST", - "/api/v1/chats", - body={"title": f"RateLimit{c}", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - chats.append(chat) - - # Отправляем сообщения подряд быстрее, чем лимит (10/сек) - # Bucket = 10 токенов, отправляем 15 сообщений без задержки - # Распределяем по чатам, чтобы не исчерпать MAX_MESSAGES_PER_CHAT - accepted = 0 - rejected = 0 - for i in range(15): - chat = chats[i % len(chats)] - req = urllib.request.Request( - BASE_URL + f"/api/v1/chats/{chat['id']}/messages", - data=json.dumps({"text": f"burst{i}"}).encode(), - headers={"Content-Type": "application/json", "X-User-Id": alice["id"]}, - method="POST", - ) - try: - urllib.request.urlopen(req) - accepted += 1 - except urllib.error.HTTPError as e: - if e.code == 429: - rejected += 1 - else: - raise AssertionError(f"неожиданный код {e.code}") - - assert accepted >= 9, f"ожидали минимум 9 успешных, получили {accepted}" - assert rejected >= 1, f"ожидали минимум 1 отказ (429), получили {rejected}" - print(f"PASS: rate_limit ({accepted} принято, {rejected} отклонено при burst)") - - # Ждём, пока bucket пополнится (1 секунды достаточно для 10 токенов) - time.sleep(1.2) - - # После паузы сообщение должно пройти — сервер восстановился - request( - "POST", - f"/api/v1/chats/{chats[0]['id']}/messages", - body={"text": "after cooldown"}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - print("PASS: rate_limit_recovery (после паузы сервер снова принимает сообщения)") - - -def main(): - print("Проверка деградации на сервере localhost:8081 с лимитами...") - - # Создаём двух пользователей для всех тестов - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:8], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:8], "display_name": "Bob"}, expected=201) - - test_user_limit() - test_message_limit_per_chat(alice, bob) - test_recovery_after_load(alice, bob) - test_rate_limit(alice, bob) - print("\n=== ВСЕ ТЕСТЫ ДЕГРАДАЦИИ ПРОЙДЕНЫ ===") - - -if __name__ == "__main__": - main() diff --git a/student-tests/test_lab1.py b/student-tests/test_lab1.py deleted file mode 100644 index d5830887..00000000 --- a/student-tests/test_lab1.py +++ /dev/null @@ -1,333 +0,0 @@ -#!/usr/bin/env python3 -"""Собственные тесты студента для lab1: негативные сценарии и конкурентность.""" -import base64 -import concurrent.futures -import json -import urllib.error -import urllib.parse -import urllib.request -import uuid - -BASE_URL = "http://localhost:8080" - - -def request(method, path, body=None, headers=None, expected=200): - """Выполнить HTTP-запрос и проверить статус ответа.""" - h = {"Accept": "application/json"} - if body is not None: - raw = json.dumps(body, ensure_ascii=False).encode("utf-8") - h["Content-Type"] = "application/json" - else: - raw = None - h.update(headers or {}) - req = urllib.request.Request(BASE_URL + path, data=raw, headers=h, method=method) - try: - resp = urllib.request.urlopen(req) - except urllib.error.HTTPError as e: - resp = e - if resp.code != expected: - data = resp.read().decode() - raise AssertionError( - f"{method} {path}: ожидался {expected}, получен {resp.code}: {data}" - ) - data = resp.read() - return json.loads(data.decode()) if data else None - - -def test_invalid_json(): - """Некорректный JSON должен возвращать 400.""" - req = urllib.request.Request( - BASE_URL + "/api/v1/users", - data=b"{not json", - headers={"Content-Type": "application/json"}, - method="POST", - ) - try: - urllib.request.urlopen(req) - raise AssertionError("ожидалась ошибка 400") - except urllib.error.HTTPError as e: - assert e.code == 400, f"ожидался 400, получен {e.code}" - data = json.loads(e.read().decode()) - assert data["error"]["code"] == "invalid_request" - print("PASS: invalid_json") - - -def test_empty_message(): - """Пустой или пробельный текст сообщения должен возвращать 400.""" - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:12], "display_name": "Bob"}, expected=201) - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Test", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - for text in ["", " ", "\t\n"]: - req = urllib.request.Request( - BASE_URL + f"/api/v1/chats/{chat['id']}/messages", - data=json.dumps({"text": text}).encode(), - headers={"Content-Type": "application/json", "X-User-Id": alice["id"]}, - method="POST", - ) - try: - urllib.request.urlopen(req) - raise AssertionError(f"ожидалась ошибка 400 для текста {repr(text)}") - except urllib.error.HTTPError as e: - assert e.code == 400, f"ожидался 400, получен {e.code}" - print("PASS: empty_message") - - -def test_duplicate_username(): - """Дублирующийся username должен возвращать 409.""" - username = "u_dup_" + uuid.uuid4().hex[:12] - request( - "POST", - "/api/v1/users", - body={"username": username, "display_name": "First"}, - expected=201, - ) - req = urllib.request.Request( - BASE_URL + "/api/v1/users", - data=json.dumps({"username": username, "display_name": "Second"}).encode(), - headers={"Content-Type": "application/json"}, - method="POST", - ) - try: - urllib.request.urlopen(req) - raise AssertionError("ожидалась ошибка 409") - except urllib.error.HTTPError as e: - assert e.code == 409, f"ожидался 409, получен {e.code}" - print("PASS: duplicate_username") - - -def test_extra_fields_rejected(): - """Лишние JSON-поля в пользователе, чате и сообщении должны возвращать 400.""" - request( - "POST", - "/api/v1/users", - body={"username": "u_extra_" + uuid.uuid4().hex[:12], "display_name": "Extra", "role": "admin"}, - expected=400, - ) - - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:12], "display_name": "Bob"}, expected=201) - - request( - "POST", - "/api/v1/chats", - body={"title": "Extra", "member_ids": [alice["id"], bob["id"]], "owner_id": alice["id"]}, - headers={"X-User-Id": alice["id"]}, - expected=400, - ) - - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Strict", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - request( - "POST", - f"/api/v1/chats/{chat['id']}/messages", - body={"text": "hello", "sender_id": bob["id"]}, - headers={"X-User-Id": alice["id"]}, - expected=400, - ) - print("PASS: extra_fields_rejected") - - -def test_foreign_chat(): - """Посторонний пользователь не должен иметь доступ к чужому чату (404).""" - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:12], "display_name": "Bob"}, expected=201) - eve = request("POST", "/api/v1/users", body={"username": "u_eve_" + uuid.uuid4().hex[:12], "display_name": "Eve"}, expected=201) - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Secret", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - # Eve не может прочитать чат - req = urllib.request.Request( - BASE_URL + f"/api/v1/chats/{chat['id']}", - headers={"X-User-Id": eve["id"]}, - method="GET", - ) - try: - urllib.request.urlopen(req) - raise AssertionError("ожидалась ошибка 404") - except urllib.error.HTTPError as e: - assert e.code == 404, f"ожидался 404, получен {e.code}" - print("PASS: foreign_chat") - - -def test_pagination(): - """Курсорная пагинация не должна пропускать или дублировать сообщения.""" - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:12], "display_name": "Bob"}, expected=201) - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Pages", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - texts = [f"msg{i}" for i in range(5)] - for t in texts: - request( - "POST", - f"/api/v1/chats/{chat['id']}/messages", - body={"text": t}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - all_ids = [] - cursor = None - while True: - url = f"/api/v1/chats/{chat['id']}/messages?limit=2" - if cursor: - url += f"&cursor={cursor}" - page = request("GET", url, headers={"X-User-Id": alice["id"]}) - all_ids.extend([m["id"] for m in page["items"]]) - cursor = page.get("next_cursor") - if cursor is None: - break - - assert len(all_ids) == 5, f"ожидалось 5 сообщений, получено {len(all_ids)}" - assert len(set(all_ids)) == 5, "обнаружены дублирующиеся сообщения в пагинации" - print("PASS: pagination") - - -def test_cursor_validation(): - """Курсор должен быть непустым, корректным и привязанным к своему чату.""" - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:12], "display_name": "Bob"}, expected=201) - chat1 = request( - "POST", - "/api/v1/chats", - body={"title": "Cursor1", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - chat2 = request( - "POST", - "/api/v1/chats", - body={"title": "Cursor2", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - for text in ["first", "second"]: - request( - "POST", - f"/api/v1/chats/{chat1['id']}/messages", - body={"text": text}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - page = request( - "GET", - f"/api/v1/chats/{chat1['id']}/messages?limit=1", - headers={"X-User-Id": alice["id"]}, - ) - cursor = page["next_cursor"] - quoted_cursor = urllib.parse.quote(cursor, safe="") - - request( - "GET", - f"/api/v1/chats/{chat2['id']}/messages?cursor={quoted_cursor}", - headers={"X-User-Id": alice["id"]}, - expected=400, - ) - - bad_content_cursor = base64.urlsafe_b64encode(b"{}").decode("ascii") - for bad_cursor in ["", "not-base64", "abcd", bad_content_cursor]: - request( - "GET", - f"/api/v1/chats/{chat1['id']}/messages?cursor={urllib.parse.quote(bad_cursor, safe='')}", - headers={"X-User-Id": alice["id"]}, - expected=400, - ) - - print("PASS: cursor_validation") - - -def test_invalid_chat_uuid(): - """Некорректный UUID чата должен давать 400, а не 404.""" - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - headers = {"X-User-Id": alice["id"]} - - request("GET", "/api/v1/chats/not-a-uuid", headers=headers, expected=400) - request("GET", "/api/v1/chats/not-a-uuid/messages", headers=headers, expected=400) - request( - "POST", - "/api/v1/chats/not-a-uuid/messages", - body={"text": "hello"}, - headers=headers, - expected=400, - ) - print("PASS: invalid_chat_uuid") - - -def test_concurrent_messages(): - """Конкурентная отправка: 100 сообщений от 10 клиентов, все должны быть уникальны.""" - alice = request("POST", "/api/v1/users", body={"username": "u_alice_" + uuid.uuid4().hex[:12], "display_name": "Alice"}, expected=201) - bob = request("POST", "/api/v1/users", body={"username": "u_bob_" + uuid.uuid4().hex[:12], "display_name": "Bob"}, expected=201) - chat = request( - "POST", - "/api/v1/chats", - body={"title": "Concurrent", "member_ids": [alice["id"], bob["id"]]}, - headers={"X-User-Id": alice["id"]}, - expected=201, - ) - - def send(i): - actor = alice if i % 2 == 0 else bob - return request( - "POST", - f"/api/v1/chats/{chat['id']}/messages", - body={"text": f"message {i}"}, - headers={"X-User-Id": actor["id"]}, - expected=201, - ) - - with concurrent.futures.ThreadPoolExecutor(max_workers=10) as ex: - futures = [ex.submit(send, i) for i in range(100)] - results = [f.result() for f in concurrent.futures.as_completed(futures)] - - msg_ids = [r["id"] for r in results] - assert len(set(msg_ids)) == 100, f"ожидалось 100 уникальных сообщений, получено {len(set(msg_ids))}" - - # Проверяем, что все 100 сообщений доступны для чтения - page = request( - "GET", - f"/api/v1/chats/{chat['id']}/messages?limit=100", - headers={"X-User-Id": alice["id"]}, - ) - assert len(page["items"]) == 100, f"ожидалось 100 элементов, получено {len(page['items'])}" - print("PASS: concurrent_messages (100 уникальных сообщений от 10 потоков)") - - -def main(): - test_invalid_json() - test_empty_message() - test_duplicate_username() - test_extra_fields_rejected() - test_foreign_chat() - test_pagination() - test_cursor_validation() - test_invalid_chat_uuid() - test_concurrent_messages() - print("\n=== ВСЕ СОБСТВЕННЫЕ ТЕСТЫ ПРОЙДЕНЫ ===") - - -if __name__ == "__main__": - main()