Create a SQL index on History.url.

This will hopefully speed up historyContains but does not seem to speed
up the completion query, unfortunately.
This commit is contained in:
Ryan Roden-Corrent 2017-06-06 21:35:57 -04:00
parent 565ba23f8c
commit 6a0fc5afd2
2 changed files with 13 additions and 0 deletions

View File

@ -78,6 +78,7 @@ class WebHistory(sql.SqlTable):
def __init__(self, parent=None):
super().__init__("History", ['url', 'title', 'atime', 'redirect'],
parent=parent)
self.create_index('HistoryIndex', 'url', where='not redirect')
self._between_query = sql.Query('SELECT * FROM History '
'where not redirect '
'and not url like "qute://%" '

View File

@ -122,6 +122,18 @@ class SqlTable(QObject):
# pylint: disable=invalid-name
self.Entry = collections.namedtuple(name + '_Entry', fields)
def create_index(self, name, field, where):
"""Create an index over this table.
Args:
name: Name of the index, should be unique.
field: Name of the field to index.
where: WHERE clause for a partial index.
"""
q = Query("CREATE INDEX IF NOT EXISTS {} ON {} ({}) WHERE {}"
.format(name, self._name, field, where))
q.run()
def __iter__(self):
"""Iterate rows in the table."""
q = Query("SELECT * FROM {}".format(self._name))