A couple search query optimizations

...which make very little difference, but they look better in the SQLite
query plan view.
This commit is contained in:
Dan Stillman 2015-06-23 14:50:17 -04:00
parent 33dedd1753
commit 3ff1ff88a9

View file

@ -888,7 +888,7 @@ Zotero.Search.idsToTempTable = function (ids) {
var tmpTable = "tmpSearchResults_" + Zotero.randomString(8); var tmpTable = "tmpSearchResults_" + Zotero.randomString(8);
return Zotero.DB.executeTransaction(function* () { return Zotero.DB.executeTransaction(function* () {
var sql = "CREATE TEMPORARY TABLE " + tmpTable + " (itemID INT)"; var sql = "CREATE TEMPORARY TABLE " + tmpTable + " (itemID INTEGER PRIMARY KEY)";
yield Zotero.DB.queryAsync(sql); yield Zotero.DB.queryAsync(sql);
var ids2 = ids ? ids.concat() : []; var ids2 = ids ? ids.concat() : [];
@ -899,9 +899,6 @@ Zotero.Search.idsToTempTable = function (ids) {
yield Zotero.DB.queryAsync(sql, chunk, { debug: false }); yield Zotero.DB.queryAsync(sql, chunk, { debug: false });
} }
var sql = "CREATE INDEX " + tmpTable + "_itemID ON " + tmpTable + "(itemID)";
yield Zotero.DB.queryAsync(sql);
return tmpTable; return tmpTable;
}); });
} }
@ -996,18 +993,13 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
} }
// Exclude deleted items (and their child items) by default // Exclude deleted items (and their child items) by default
sql += " WHERE itemID " + (deleted ? "" : "NOT ") + "IN " sql += " WHERE itemID " + (deleted ? "" : "NOT ") + "IN (SELECT itemID FROM deletedItems) "
+ "(" + "AND itemID " + (deleted ? "" : "NOT ") + "IN (SELECT itemID FROM itemNotes "
+ "SELECT itemID FROM deletedItems "
+ "UNION "
+ "SELECT itemID FROM itemNotes "
+ "WHERE parentItemID IS NOT NULL AND " + "WHERE parentItemID IS NOT NULL AND "
+ "parentItemID IN (SELECT itemID FROM deletedItems) " + "parentItemID IN (SELECT itemID FROM deletedItems)) "
+ "UNION " + "AND itemID " + (deleted ? "" : "NOT ") + "IN (SELECT itemID FROM itemAttachments "
+ "SELECT itemID FROM itemAttachments "
+ "WHERE parentItemID IS NOT NULL AND " + "WHERE parentItemID IS NOT NULL AND "
+ "parentItemID IN (SELECT itemID FROM deletedItems) " + "parentItemID IN (SELECT itemID FROM deletedItems))";
+ ")";
if (noChildren){ if (noChildren){
sql += " AND (itemID NOT IN (SELECT itemID FROM itemNotes " sql += " AND (itemID NOT IN (SELECT itemID FROM itemNotes "