I have a SQLite table that's about 30 million rows by 500 columns. Three of those columns are:
CREATE TABLE core (
state TEXT,
year INTEGER,
randInt INTEGER,
);
My primary use for this table is to SELECT
subsets, either by state
-year
pairs or by comparison with randInt
. randInt
is a random integer that ranges from 0 to 100.
Examples of state-year selection:
SELECT * WHERE state='MA' AND year=1999;
SELECT * WHERE (state='MA' AND year=1999) OR (state='NJ' AND year=1998);
Examples of randInt selection:
SELECT * WHERE randInt < 10;
SELECT * WHERE randInt = 10;
These two types of selections comprise more than 95% of the database queries I will be doing. Is there any way to optimize the table specifically for them?
I guess I want to explicitly CREATE INDEX
for randInt
and a compound index for state,year
, but I don't know if having one interferes with the other, and I don't know how to create compound indices.
Should I turn off indexing on all the other 497 columns, since I will rarely if ever index over them?