Skip to content

Instantly share code, notes, and snippets.

@karlb
Last active December 17, 2022 18:25
Show Gist options
  • Save karlb/5cf6811b4d63b4035304feed6cc60bfd to your computer and use it in GitHub Desktop.
Save karlb/5cf6811b4d63b4035304feed6cc60bfd to your computer and use it in GitHub Desktop.
SQLite memo
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