simonw / simonw/sqlite-utils

A way of creating indexes on newly created tables

Open
#349 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement python-library
Dominant language
Python
Stars
2.2k
Forks
172
Avg merge
9m
Merged PRs (30d)
1

Description

I'm writing code for https://github.com/simonw/git-history/issues/33 that creates a table inside a loop:

item_pk = db[item_table].lookup(
    {"_item_id": item_id},
    item_to_insert,
    column_order=("_id", "_item_id"),
    pk="_id",
)

I need to look things up by _item_id on this table, which means I need an index on that column (the table can get very big).

But there's no mechanism in SQLite utils to detect if the table was created for the first time and add an index to it. And I don't want to run CREATE INDEX IF NOT EXISTS every time through the loop.

This should work like the foreign_keys= mechanism.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the db[item_table].lookup() entry point and the existing foreign_keys= mechanism. Define how indexes should be supplied when a table is first created, ensure repeated loop iterations do not recreate them, and verify that lookups by _item_id use the new index.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.