Skip to content

Commit

Permalink
Avoid potentially expensive len() call in value index estimation.
Browse files Browse the repository at this point in the history
Instead iterate over unique values and break if we can get more than
`MAX_DISTINCT_VALUES` values. Also correctly identify empty indexes like the
DateRangeIndex, which only returns values when the name argument is provided
to the uniqueValues method with either the `since` or `until` field.
  • Loading branch information
hannosch committed Oct 17, 2013
1 parent 155a46c commit 3770bc9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Products/ZCatalog/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,15 @@ def valueindexes(self):
for name, index in indexes.items():
if IUniqueValueIndex.providedBy(index):
values = index.uniqueValues()
if values and len(list(values)) < MAX_DISTINCT_VALUES:
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)
Expand Down

0 comments on commit 3770bc9

Please sign in to comment.