Query plan gate
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "molodetz"
|
name = "molodetz"
|
||||||
version = "1.0.2"
|
version = "1.0.3"
|
||||||
description = "Molodetz, a calm community blog roll."
|
description = "Molodetz, a calm community blog roll."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# retoor <retoor@molodetz.nl>
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from tests.conftest import TEST_DATA_DIR
|
||||||
|
|
||||||
|
QUERIES = [
|
||||||
|
("idx_posts_published", "SELECT * FROM posts WHERE topic = 'rol' AND status = 'published' AND deleted_at IS NULL ORDER BY published_at DESC LIMIT 25"),
|
||||||
|
("idx_posts_slug", "SELECT * FROM posts WHERE slug = 'x'"),
|
||||||
|
("idx_sessions_token", "SELECT * FROM sessions WHERE token = 'x'"),
|
||||||
|
("idx_users_api_key", "SELECT * FROM users WHERE api_key = 'x'"),
|
||||||
|
("idx_media_items_kind", "SELECT * FROM media_items WHERE kind = 'flyer' AND deleted_at IS NULL ORDER BY position, id"),
|
||||||
|
("idx_notifications_user", "SELECT * FROM notifications WHERE user_uid = 'x' ORDER BY created_at DESC LIMIT 50"),
|
||||||
|
("idx_audit_log_created", "SELECT uid FROM audit_log WHERE created_at < '2020-01-01'"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("index,sql", QUERIES, ids=[item[0] for item in QUERIES])
|
||||||
|
def test_index_is_used_without_temp_btree(app_server, index, sql):
|
||||||
|
connection = sqlite3.connect(TEST_DATA_DIR / "molodetz.db")
|
||||||
|
try:
|
||||||
|
plan = " | ".join(row[-1] for row in connection.execute(f"EXPLAIN QUERY PLAN {sql}"))
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
assert f"USING INDEX {index}" in plan or f"USING COVERING INDEX {index}" in plan, plan
|
||||||
|
assert "TEMP B-TREE" not in plan, plan
|
||||||
Reference in New Issue
Block a user