Last active
December 17, 2022 18:25
-
-
Save karlb/5cf6811b4d63b4035304feed6cc60bfd to your computer and use it in GitHub Desktop.
SQLite memo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
conn = sqlite3.connect(":memory:") | |
conn.row_factory = sqlite3.Row | |
def print_query_plan(query, bindings={}): | |
depth_of = {0: -1} | |
result = conn.execute("EXPLAIN QUERY PLAN " + query, bindings).fetchall() | |
for r in result: | |
depth = depth_of[r['parent']] + 1 | |
depth_of[r['id']] = depth | |
print('| ' * depth + r['detail']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment