diff --git a/etiquette/constants.py b/etiquette/constants.py index 4d6b5e8..548034e 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -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, diff --git a/utilities/database_upgrader/database_upgrader.py b/utilities/database_upgrader/database_upgrader.py index 0e420da..32f6c8e 100644 --- a/utilities/database_upgrader/database_upgrader.py +++ b/utilities/database_upgrader/database_upgrader.py @@ -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