DB V12: Add (photoid, tagid) index to photo_tag_rel.

This commit is contained in:
voussoir 2018-03-21 19:00:13 -07:00
parent acc9b67a20
commit 1e42f1ea4e
2 changed files with 13 additions and 1 deletions

View file

@ -42,7 +42,7 @@ FILENAME_BADCHARS = '\\/:*?<>|"'
# Note: Setting user_version pragma in init sequence is safe because it only
# happens after the out-of-date check occurs, so no chance of accidentally
# overwriting it.
DATABASE_VERSION = 11
DATABASE_VERSION = 12
DB_INIT = '''
PRAGMA cache_size = 10000;
PRAGMA count_changes = OFF;
@ -161,6 +161,7 @@ CREATE TABLE IF NOT EXISTS photo_tag_rel(
);
CREATE INDEX IF NOT EXISTS index_photo_tag_rel_photoid on photo_tag_rel(photoid);
CREATE INDEX IF NOT EXISTS index_photo_tag_rel_tagid on photo_tag_rel(tagid);
CREATE INDEX IF NOT EXISTS index_photo_tag_rel_photoid_tagid on photo_tag_rel(photoid, tagid);
----------------------------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS tag_group_rel(
parentid TEXT NOT NULL,

View file

@ -227,6 +227,17 @@ def upgrade_10_to_11(photodb):
cur.execute('PRAGMA foreign_keys = ON')
def upgrade_11_to_12(photodb):
'''
Added multicolumn (photoid, tagid) index to the photo_tag_rel table to
improve the speed of individual relation searching, important for the
new intersection-based search.
'''
query = '''
CREATE INDEX IF NOT EXISTS index_photo_tag_rel_photoid_tagid on photo_tag_rel(photoid, tagid)
'''
photodb.sql.cursor().execute(query)
def upgrade_all(data_directory):
'''
Given the directory containing a phototagger database, apply all of the