Skip to content

Commit

Permalink
we can exclude some indexes from queryplan
Browse files Browse the repository at this point in the history
  • Loading branch information
tdesvenain committed Jun 25, 2018
1 parent 41da385 commit bc7f90a
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/Products/ZCatalog/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from zope.dottedname.resolve import resolve

MAX_DISTINCT_VALUES = 10
EXCLUDED_INDEXES = ['id', 'UID', 'Date', 'getId', 'Title', 'sortable_title', 'path',
'modified', 'expires', 'created', 'effective', 'start', 'end',
'targetUID', 'sourceUID', 'targetId', 'relationship']
REFRESH_RATE = 100
VALUE_INDEX_KEY = 'VALUE_INDEXES'

Expand Down Expand Up @@ -199,20 +202,22 @@ def valueindexes(self):

value_indexes = set()
for name, index in indexes.items():
if IUniqueValueIndex.providedBy(index):
values = index.uniqueValues()
i = 0
for value in values:
# the total number of unique values might be large and
# expensive to load, so we only check if we can get
# more than MAX_DISTINCT_VALUES
if i >= MAX_DISTINCT_VALUES:
break
i += 1
if i > 0 and i < MAX_DISTINCT_VALUES:
# Only consider indexes which actually return a number
# greater than zero
value_indexes.add(name)
if index.id in EXCLUDED_INDEXES or not IUniqueValueIndex.providedBy(index):
continue

values = index.uniqueValues()
i = 0
for value in values:
# the total number of unique values might be large and
# expensive to load, so we only check if we can get
# more than MAX_DISTINCT_VALUES
if i >= MAX_DISTINCT_VALUES:
break
i += 1
if i > 0 and i < MAX_DISTINCT_VALUES:
# Only consider indexes which actually return a number
# greater than zero
value_indexes.add(name)

value_indexes = frozenset(value_indexes)
PriorityMap.set_entry(self.cid, VALUE_INDEX_KEY, value_indexes)
Expand Down

0 comments on commit bc7f90a

Please sign in to comment.