Add cardinality option to Index Usage

Closes #13426
This commit is contained in:
Cédric Krier
2024-07-27 17:49:13 +02:00
parent 084cd424ce
commit 234daa0f99
5 changed files with 26 additions and 7 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add cardinality option to Index Usage
* Allow configuring TinyMCE license key
* Add tools to apply types to SQLite select queries
* Compress RPC responses
+5 -4
View File
@@ -798,23 +798,24 @@ Available options are:
Apply unaccent function if the database supports it.
.. attribute:: Index.Usage(\*\*options)
.. attribute:: Index.Usage([cardinality[, \*\*options]])
Represent a usage of a SQL expression.
Available cardinality is ``low``, ``normal`` (default) and ``high``.
Available options are:
* ``collation``: the name of the collation
* ``order``: the sort order
.. attribute:: Index.Equality(\*\*options)
.. attribute:: Index.Equality([cardinality[, \*\*options]])
Represent an equality usage.
.. attribute:: Index.Range(\*\*options)
.. attribute:: Index.Range([cardinality[, \*\*options]])
Represent an range usage.
.. attribute:: Index.Similarity(\*\*options)
.. attribute:: Index.Similarity([cardinality[, \*\*options]])
Represent a similar usage only for text.
Additional options are available:
+2 -1
View File
@@ -635,7 +635,8 @@ class HashTranslator(IndexMixin, IndexTranslatorInterface):
@classmethod
def score(cls, index):
if (len(index.expressions) > 1
or index.expressions[0][1].__class__.__name__ != 'Equality'):
or index.expressions[0][1].__class__.__name__ != 'Equality'
or index.expressions[0][1].cardinality != 'high'):
return 0
if index.options.get('include'):
return 0
+5 -2
View File
@@ -232,9 +232,11 @@ class Index:
return self.expression.params
class Usage:
__slots__ = ('options',)
__slots__ = ('options', 'cardinality')
def __init__(self, **options):
def __init__(self, cardinality='normal', **options):
assert cardinality in {'low', 'normal', 'high'}
self.cardinality = cardinality
self.options = options
def __hash__(self):
@@ -242,6 +244,7 @@ class Index:
def __eq__(self, other):
return (self.__class__ == other.__class__
and self.cardinality == other.cardinality
and self.options == other.options)
class Equality(Usage):
+13
View File
@@ -77,6 +77,19 @@ class ModelIndexTestCase(TestCase):
self.assertNotEqual(index1, index2)
def test_index_inequality_usage_cardinality(self):
"Test Index inequality on usage cardinality"
table1 = Table('test')
index1 = Index(
table1,
(table1.name, Index.Equality(cardinality='low')))
table2 = Table('test')
index2 = Index(
table2,
(table2.name, Index.Equality(cardinality='high')))
self.assertNotEqual(index1, index2)
def test_index_inequality_usage_option(self):
"Test Index inequality on usage option"
table1 = Table('test')