From a2dfc4455bdb87a652086e8f9c451e1618ae5ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 27 Jul 2024 18:36:14 +0200 Subject: [PATCH] Refine index definition - Set low and high cardinality to index usage - Use Range usage for numerical expression instead of Equality --- modules/account/account.py | 10 +++---- modules/account/move.py | 26 +++++++++---------- modules/account_asset/asset.py | 2 +- modules/account_budget/account.py | 4 +-- modules/account_dunning/dunning.py | 2 +- modules/account_es_sii/account.py | 2 +- modules/account_invoice/invoice.py | 9 ++++--- modules/account_invoice_defer/account.py | 2 +- modules/account_payment/payment.py | 2 +- modules/account_payment_braintree/account.py | 2 +- modules/account_payment_sepa/payment.py | 4 +-- modules/account_payment_stripe/payment.py | 2 +- modules/account_statement/statement.py | 4 +-- modules/account_stock_eu/account_stock_eu.py | 2 +- modules/account_stock_eu/stock.py | 4 +-- modules/account_stock_landed_cost/account.py | 5 +++- .../account_stock_shipment_cost/account.py | 5 +++- modules/analytic_account/line.py | 2 +- modules/attendance/attendance.py | 2 +- modules/authentication_sms/res.py | 3 ++- modules/currency/currency.py | 2 +- .../marketing_automation.py | 5 ++-- modules/marketing_email/marketing.py | 6 ++--- modules/party/country.py | 4 +-- modules/party/party.py | 4 +-- modules/party_relationship/party.py | 4 +-- modules/product/product.py | 6 ++--- modules/production/production.py | 2 +- modules/production_work/work.py | 4 +-- modules/purchase/purchase.py | 8 +++--- modules/purchase_amendment/purchase.py | 2 +- .../purchase_blanket_agreement/purchase.py | 2 +- modules/purchase_request/purchase_request.py | 2 +- .../purchase_request_quotation/purchase.py | 2 +- modules/purchase_requisition/purchase.py | 2 +- modules/sale/sale.py | 8 +++--- modules/sale_amendment/sale.py | 2 +- modules/sale_blanket_agreement/sale.py | 2 +- modules/sale_complaint/complaint.py | 2 +- modules/sale_opportunity/opportunity.py | 4 +-- modules/sale_point/sale.py | 12 ++++++--- .../sale.py | 2 +- modules/sale_subscription/subscription.py | 2 +- modules/sale_supply_drop_shipment/stock.py | 2 +- modules/stock/inventory.py | 5 +++- modules/stock/location.py | 4 +-- modules/stock/move.py | 2 +- modules/stock/period.py | 6 ++--- modules/stock/product.py | 6 ++--- modules/stock/shipment.py | 10 +++---- modules/stock_forecast/forecast.py | 2 +- modules/stock_lot/stock.py | 8 +++--- .../stock_quantity_early_planning/stock.py | 2 +- modules/stock_quantity_issue/stock.py | 2 +- modules/timesheet/line.py | 20 +++++++------- modules/timesheet_cost/company.py | 2 +- modules/web_user/user.py | 12 ++++++--- trytond/trytond/ir/error.py | 2 +- trytond/trytond/ir/rule.py | 2 +- trytond/trytond/ir/session.py | 6 ++--- trytond/trytond/ir/translation.py | 18 ++++++------- trytond/trytond/ir/trigger.py | 2 +- trytond/trytond/ir/ui/view.py | 14 +++++----- trytond/trytond/res/user.py | 10 +++---- 64 files changed, 171 insertions(+), 149 deletions(-) diff --git a/modules/account/account.py b/modules/account/account.py index 7e9702764d..f819db44a7 100644 --- a/modules/account/account.py +++ b/modules/account/account.py @@ -273,7 +273,7 @@ class Type( # Index for receivable/payable balance Index( table, - (table.id, Index.Range()), + (table.id, Index.Range(cardinality='high')), where=table.receivable | table.payable), }) @@ -990,8 +990,8 @@ class Account( cls._sql_indexes.add( Index( table, - (table.left, Index.Range()), - (table.right, Index.Range()))) + (table.left, Index.Range(cardinality='high')), + (table.right, Index.Range(cardinality='high')))) @classmethod def __register__(cls, module_name): @@ -1704,8 +1704,8 @@ class AccountDeferral(ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.fiscalyear, Index.Equality()), - (t.account, Index.Equality()))) + (t.fiscalyear, Index.Range()), + (t.account, Index.Range()))) @classmethod def __register__(cls, module_name): diff --git a/modules/account/move.py b/modules/account/move.py index 0453b190c8..cff30196b0 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -149,12 +149,12 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): readonly=False, instantiate=0, fresh_session=True), }) cls._sql_indexes.update({ - Index(t, (t.period, Index.Equality())), + Index(t, (t.period, Index.Range())), Index(t, (t.date, Index.Range()), (t.number, Index.Range())), Index( t, - (t.journal, Index.Equality()), - (t.period, Index.Equality())), + (t.journal, Index.Range()), + (t.period, Index.Range())), }) @classmethod @@ -1072,26 +1072,26 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): cls._sql_indexes.update({ Index( table, - (table.account, Index.Equality()), - (table.party, Index.Equality())), - Index(table, (table.reconciliation, Index.Equality())), + (table.account, Index.Range()), + (table.party, Index.Range())), + Index(table, (table.reconciliation, Index.Range())), # Index for General Ledger Index( table, - (table.move, Index.Equality()), - (table.account, Index.Equality())), + (table.move, Index.Range()), + (table.account, Index.Range())), # Index for account.account.party Index( table, - (table.account, Index.Equality()), - (table.party, Index.Equality()), - (table.id, Index.Equality()), + (table.account, Index.Range()), + (table.party, Index.Range()), + (table.id, Index.Range(cardinality='high')), where=table.party != Null), # Index for receivable/payable balance Index( table, - (table.account, Index.Equality()), - (table.party, Index.Equality()), + (table.account, Index.Range()), + (table.party, Index.Range()), where=table.reconciliation == Null), }) diff --git a/modules/account_asset/asset.py b/modules/account_asset/asset.py index 4fa0270053..6adce70ee1 100644 --- a/modules/account_asset/asset.py +++ b/modules/account_asset/asset.py @@ -208,7 +208,7 @@ class Asset(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( table, - (table.state, Index.Equality()), + (table.state, Index.Equality(cardinality='low')), where=table.state.in_(['draft', 'running']))) cls._transitions |= set(( ('draft', 'running'), diff --git a/modules/account_budget/account.py b/modules/account_budget/account.py index d44d371885..18cfe90465 100644 --- a/modules/account_budget/account.py +++ b/modules/account_budget/account.py @@ -169,8 +169,8 @@ class BudgetLineMixin( cls._sql_indexes.add( Index( t, - (t.left, Index.Range()), - (t.right, Index.Range()))) + (t.left, Index.Range(cardinality='high')), + (t.right, Index.Range(cardinality='high')))) cls.__access__.add('budget') @classmethod diff --git a/modules/account_dunning/dunning.py b/modules/account_dunning/dunning.py index 17c7f18895..e0a0276a90 100644 --- a/modules/account_dunning/dunning.py +++ b/modules/account_dunning/dunning.py @@ -131,7 +131,7 @@ class Dunning(ModelSQL, ModelView): cls._sql_indexes.add( Index( table, - (table.state, Index.Equality()), + (table.state, Index.Equality(cardinality='low')), where=table.state.in_(['draft', 'waiting']))) cls._active_field = 'active' cls._buttons.update({ diff --git a/modules/account_es_sii/account.py b/modules/account_es_sii/account.py index d9f51cef20..ed1bd18f93 100644 --- a/modules/account_es_sii/account.py +++ b/modules/account_es_sii/account.py @@ -298,7 +298,7 @@ class InvoiceSII(ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['pending', 'wrong', 'rejected']))) @classmethod diff --git a/modules/account_invoice/invoice.py b/modules/account_invoice/invoice.py index d5b0bad1e9..fc03a3533c 100644 --- a/modules/account_invoice/invoice.py +++ b/modules/account_invoice/invoice.py @@ -360,24 +360,25 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin): Index(t, (t.reference, Index.Similarity())), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'validated', 'posted'])), Index(t, (t.total_amount_cache, Index.Range())), Index( t, - (t.total_amount_cache, Index.Equality()), + (t.total_amount_cache, Index.Equality(cardinality='low')), include=[t.id], where=t.total_amount_cache == Null), Index(t, (t.untaxed_amount_cache, Index.Range())), Index( t, - (t.untaxed_amount_cache, Index.Equality()), + (t.untaxed_amount_cache, + Index.Equality(cardinality='low')), include=[t.id], where=t.untaxed_amount_cache == Null), Index(t, (t.tax_amount_cache, Index.Range())), Index( t, - (t.tax_amount_cache, Index.Equality()), + (t.tax_amount_cache, Index.Equality(cardinality='low')), include=[t.id], where=t.tax_amount_cache == Null), }) diff --git a/modules/account_invoice_defer/account.py b/modules/account_invoice_defer/account.py index 2503ef92b7..8c0c36ea1f 100644 --- a/modules/account_invoice_defer/account.py +++ b/modules/account_invoice_defer/account.py @@ -131,7 +131,7 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView): ] cls._sql_indexes.add( Index( - table, (table.state, Index.Equality()), + table, (table.state, Index.Equality(cardinality='low')), where=table.state.in_(['draft', 'running']))) cls.journal.domain = [ If(Eval('type') == 'out', diff --git a/modules/account_payment/payment.py b/modules/account_payment/payment.py index d9dec7d5f0..b1e7acf1cd 100644 --- a/modules/account_payment/payment.py +++ b/modules/account_payment/payment.py @@ -386,7 +386,7 @@ class Payment(Workflow, ModelSQL, ModelView): t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'submitted', 'approved', 'processing']))) cls._order.insert(0, ('date', 'DESC')) diff --git a/modules/account_payment_braintree/account.py b/modules/account_payment_braintree/account.py index 20f2a3bcf0..9dd13bde45 100644 --- a/modules/account_payment_braintree/account.py +++ b/modules/account_payment_braintree/account.py @@ -585,7 +585,7 @@ class PaymentBraintreeRefund(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'submitted', 'approved', 'processing']))) cls.__access__.add('payment') diff --git a/modules/account_payment_sepa/payment.py b/modules/account_payment_sepa/payment.py index b8270b08be..7664ddd508 100644 --- a/modules/account_payment_sepa/payment.py +++ b/modules/account_payment_sepa/payment.py @@ -582,7 +582,7 @@ class Mandate(Workflow, ModelSQL, ModelView): ] cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'requested']))) @classmethod @@ -834,7 +834,7 @@ class Message(Workflow, ModelSQL, ModelView): t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'waiting']))) cls._transitions |= { ('draft', 'waiting'), diff --git a/modules/account_payment_stripe/payment.py b/modules/account_payment_stripe/payment.py index 48840a26d4..06855d4dc9 100644 --- a/modules/account_payment_stripe/payment.py +++ b/modules/account_payment_stripe/payment.py @@ -773,7 +773,7 @@ class Refund(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'submitted', 'approved', 'processing']))) cls.__access__.add('payment') diff --git a/modules/account_statement/statement.py b/modules/account_statement/statement.py index 00cf7f66ea..715ea6ef0c 100644 --- a/modules/account_statement/statement.py +++ b/modules/account_statement/statement.py @@ -134,11 +134,11 @@ class Statement(Workflow, ModelSQL, ModelView): cls._sql_indexes.update({ Index( t, - (t.journal, Index.Equality()), + (t.journal, Index.Range()), (t.date, Index.Range(order='DESC'))), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'validated'])), }) cls._order[0] = ('id', 'DESC') diff --git a/modules/account_stock_eu/account_stock_eu.py b/modules/account_stock_eu/account_stock_eu.py index 3a6b8dd351..8eb43f7f08 100644 --- a/modules/account_stock_eu/account_stock_eu.py +++ b/modules/account_stock_eu/account_stock_eu.py @@ -132,7 +132,7 @@ class IntrastatDeclaration(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state == 'opened')) cls._order = [ ('month', 'DESC'), diff --git a/modules/account_stock_eu/stock.py b/modules/account_stock_eu/stock.py index b19d9eed74..a50bbaf8e9 100644 --- a/modules/account_stock_eu/stock.py +++ b/modules/account_stock_eu/stock.py @@ -104,8 +104,8 @@ class Move(metaclass=PoolMeta): cls._sql_indexes.add( Index( t, - (t.intrastat_declaration, Index.Equality()), - (t.company, Index.Equality()), + (t.intrastat_declaration, Index.Range()), + (t.company, Index.Range()), where=(t.intrastat_type != Null) & (t.state == 'done'))) @fields.depends( diff --git a/modules/account_stock_landed_cost/account.py b/modules/account_stock_landed_cost/account.py index 821575efc3..9f9320f981 100644 --- a/modules/account_stock_landed_cost/account.py +++ b/modules/account_stock_landed_cost/account.py @@ -136,7 +136,10 @@ class LandedCost(Workflow, ModelSQL, ModelView, MatchMixin): super(LandedCost, cls).__setup__() t = cls.__table__() cls._sql_indexes.add( - Index(t, (t.state, Index.Equality()), where=t.state == 'draft')) + Index( + t, + (t.state, Index.Equality(cardinality='low')), + where=t.state == 'draft')) cls._order = [ ('number', 'DESC'), ('id', 'DESC'), diff --git a/modules/account_stock_shipment_cost/account.py b/modules/account_stock_shipment_cost/account.py index 93cd56e337..88d50ee148 100644 --- a/modules/account_stock_shipment_cost/account.py +++ b/modules/account_stock_shipment_cost/account.py @@ -127,7 +127,10 @@ class ShipmentCost(Workflow, ModelSQL, ModelView): super().__setup__() t = cls.__table__() cls._sql_indexes.add( - Index(t, (t.state, Index.Equality()), where=t.state == 'draft')) + Index( + t, + (t.state, Index.Equality(cardinality='low')), + where=t.state == 'draft')) cls._order.insert(0, ('number', 'DESC')) cls._transitions |= set(( ('draft', 'posted'), diff --git a/modules/analytic_account/line.py b/modules/analytic_account/line.py index 571eaa5e88..ecaa9dbeee 100644 --- a/modules/analytic_account/line.py +++ b/modules/analytic_account/line.py @@ -46,7 +46,7 @@ class Line(ModelSQL, ModelView): 'account.msg_line_debit_credit'), ] cls._sql_indexes.update({ - Index(t, (t.account, Index.Equality())), + Index(t, (t.account, Index.Range())), Index(t, (t.date, Index.Range())), }) cls._order.insert(0, ('date', 'ASC')) diff --git a/modules/attendance/attendance.py b/modules/attendance/attendance.py index 9580f94aa5..8416b12155 100644 --- a/modules/attendance/attendance.py +++ b/modules/attendance/attendance.py @@ -182,7 +182,7 @@ class Period(Workflow, ModelSQL, ModelView): Index( t, (t.company, Index.Equality()), - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), (t.ends_at, Index.Range(order='DESC')))) cls._transitions |= set(( ('draft', 'closed'), diff --git a/modules/authentication_sms/res.py b/modules/authentication_sms/res.py index 4b8290256f..db675b1b5e 100644 --- a/modules/authentication_sms/res.py +++ b/modules/authentication_sms/res.py @@ -67,7 +67,8 @@ class UserLoginSMSCode(ModelSQL): def __setup__(cls): super().__setup__() t = cls.__table__() - cls._sql_indexes.add(Index(t, (t.user_id, Index.Equality()))) + cls._sql_indexes.add(Index( + t, (t.user_id, Index.Equality(cardinality='high')))) @classmethod def default_code(cls): diff --git a/modules/currency/currency.py b/modules/currency/currency.py index 1332cc13a6..747cf5d502 100644 --- a/modules/currency/currency.py +++ b/modules/currency/currency.py @@ -288,7 +288,7 @@ class CurrencyRate(ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.currency, Index.Equality()), + (t.currency, Index.Range()), (t.date, Index.Range()), order='DESC')) cls._order.insert(0, ('date', 'DESC')) diff --git a/modules/marketing_automation/marketing_automation.py b/modules/marketing_automation/marketing_automation.py index db9ba6b0ea..fee5ebf929 100644 --- a/modules/marketing_automation/marketing_automation.py +++ b/modules/marketing_automation/marketing_automation.py @@ -138,7 +138,8 @@ class Scenario( t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'running']))) cls._transitions |= set(( ('draft', 'running'), @@ -917,7 +918,7 @@ class RecordActivity(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['waiting']))) cls._transitions |= set(( ('waiting', 'done'), diff --git a/modules/marketing_email/marketing.py b/modules/marketing_email/marketing.py index bb6c6deb58..691c29994e 100644 --- a/modules/marketing_email/marketing.py +++ b/modules/marketing_email/marketing.py @@ -80,8 +80,8 @@ class Email(DeactivableMixin, ModelSQL, ModelView): ] cls._sql_indexes.add(Index( t, - (t.list_, Index.Equality()), - (t.email, Index.Equality()))) + (t.list_, Index.Range()), + (t.email, Index.Equality(cardinality='high')))) @classmethod def default_email_token(cls, nbytes=None): @@ -375,7 +375,7 @@ class Message(Workflow, ModelSQL, ModelView): t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'sending']))) cls._transitions |= set([ ('draft', 'sending'), diff --git a/modules/party/country.py b/modules/party/country.py index e94dc2600b..fcd97fa173 100644 --- a/modules/party/country.py +++ b/modules/party/country.py @@ -16,6 +16,6 @@ class PostalCode(metaclass=PoolMeta): Index( t, (Index.Unaccent(t.city), Index.Similarity()), - (t.country, Index.Equality()), - (t.subdivision, Index.Equality())), + (t.country, Index.Range()), + (t.subdivision, Index.Range())), }) diff --git a/modules/party/party.py b/modules/party/party.py index 1f7146ef04..7d6bcec5b4 100644 --- a/modules/party/party.py +++ b/modules/party/party.py @@ -102,8 +102,8 @@ class Party( ('code_uniq', Unique(t, t.code), 'party.msg_party_code_unique') ] cls._sql_indexes.update({ - Index(t, (t.code, Index.Equality())), - Index(t, (t.code, Index.Similarity())), + Index(t, (t.code, Index.Equality(cardinality='high'))), + Index(t, (t.code, Index.Similarity(cardinality='high'))), }) cls._order.insert(0, ('distance', 'ASC NULLS LAST')) cls._order.insert(1, ('name', 'ASC')) diff --git a/modules/party_relationship/party.py b/modules/party_relationship/party.py index e46ac27a1b..961443f274 100644 --- a/modules/party_relationship/party.py +++ b/modules/party_relationship/party.py @@ -72,8 +72,8 @@ class Relation(ModelSQL): if not callable(cls.table_query): t = cls.__table__() cls._sql_indexes.update({ - Index(t, (t.from_, Index.Equality())), - Index(t, (t.to, Index.Equality())), + Index(t, (t.from_, Index.Range())), + Index(t, (t.to, Index.Range())), }) def get_active(self, name): diff --git a/modules/product/product.py b/modules/product/product.py index 20c9e58db1..f31b2a8b60 100644 --- a/modules/product/product.py +++ b/modules/product/product.py @@ -446,7 +446,7 @@ class Product( 'product.msg_product_code_unique'), ] cls._sql_indexes.add( - Index(t, (t.code, Index.Similarity()))) + Index(t, (t.code, Index.Similarity(cardinality='high')))) for attr in dir(Template): tfield = getattr(Template, attr) @@ -819,8 +819,8 @@ class ProductIdentifier(sequence_ordered(), ModelSQL, ModelView): cls._sql_indexes.update({ Index( t, - (t.product, Index.Equality()), - (t.code, Index.Similarity())), + (t.product, Index.Range()), + (t.code, Index.Similarity(cardinality='high'))), }) @property diff --git a/modules/production/production.py b/modules/production/production.py index 99ff55a88e..f8b48c5ed9 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -168,7 +168,7 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): Index(t, (t.reference, Index.Similarity())), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'request', 'draft', 'waiting', 'assigned', 'running'])), diff --git a/modules/production_work/work.py b/modules/production_work/work.py index a89a301b57..58e1627257 100644 --- a/modules/production_work/work.py +++ b/modules/production_work/work.py @@ -155,7 +155,7 @@ class Work(sequence_ordered(), ModelSQL, ModelView): t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['request', 'draft', 'waiting', 'running']))) cls._buttons.update({ 'start': { @@ -348,7 +348,7 @@ class WorkCycle(Workflow, ModelSQL, ModelView): t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'running']))) cls._transitions |= set(( ('draft', 'running'), diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index f17183ddd5..8d25d34439 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -254,20 +254,20 @@ class Purchase( t = cls.__table__() cls._sql_indexes.update({ Index(t, (t.reference, Index.Similarity())), - Index(t, (t.party, Index.Equality())), + Index(t, (t.party, Index.Range())), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'quotation', 'confirmed', 'processing'])), Index( t, - (t.invoice_state, Index.Equality()), + (t.invoice_state, Index.Equality(cardinality='low')), where=t.invoice_state.in_([ 'none', 'waiting', 'exception'])), Index( t, - (t.shipment_state, Index.Equality()), + (t.shipment_state, Index.Equality(cardinality='low')), where=t.shipment_state.in_([ 'none', 'waiting', 'exception'])), }) diff --git a/modules/purchase_amendment/purchase.py b/modules/purchase_amendment/purchase.py index f973ff24e2..a9ea0f2b3c 100644 --- a/modules/purchase_amendment/purchase.py +++ b/modules/purchase_amendment/purchase.py @@ -74,7 +74,7 @@ class Amendment(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state == 'draft')) cls._order = [ ('date', 'DESC'), diff --git a/modules/purchase_blanket_agreement/purchase.py b/modules/purchase_blanket_agreement/purchase.py index 2305331007..167feae625 100644 --- a/modules/purchase_blanket_agreement/purchase.py +++ b/modules/purchase_blanket_agreement/purchase.py @@ -196,7 +196,7 @@ class BlanketAgreement(Workflow, ModelSQL, ModelView): cls._sql_indexes.update({ Index(t, (t.reference, Index.Similarity())), Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'running'])), }) cls._order = [ diff --git a/modules/purchase_request/purchase_request.py b/modules/purchase_request/purchase_request.py index 6d2807a531..a2ded88dc8 100644 --- a/modules/purchase_request/purchase_request.py +++ b/modules/purchase_request/purchase_request.py @@ -114,7 +114,7 @@ class PurchaseRequest(ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'purchased', 'exception']))) cls._order[0] = ('id', 'DESC') cls._buttons.update({ diff --git a/modules/purchase_request_quotation/purchase.py b/modules/purchase_request_quotation/purchase.py index 5b779eac35..143225ea46 100644 --- a/modules/purchase_request_quotation/purchase.py +++ b/modules/purchase_request_quotation/purchase.py @@ -140,7 +140,7 @@ class Quotation(Workflow, ModelSQL, ModelView): cls._sql_indexes.update({ Index(t, (t.reference, Index.Similarity())), Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'sent'])), }) cls._transitions |= set(( diff --git a/modules/purchase_requisition/purchase.py b/modules/purchase_requisition/purchase.py index f577a6aa43..07e949be8c 100644 --- a/modules/purchase_requisition/purchase.py +++ b/modules/purchase_requisition/purchase.py @@ -136,7 +136,7 @@ class PurchaseRequisition(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'waiting', 'approved', 'processing']))) cls._transitions |= set(( diff --git a/modules/sale/sale.py b/modules/sale/sale.py index 94c5b74b24..f1fbcc80da 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -297,20 +297,20 @@ class Sale( t = cls.__table__() cls._sql_indexes.update({ Index(t, (t.reference, Index.Similarity())), - Index(t, (t.party, Index.Equality())), + Index(t, (t.party, Index.Range())), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'quotation', 'confirmed', 'processing'])), Index( t, - (t.invoice_state, Index.Equality()), + (t.invoice_state, Index.Equality(cardinality='low')), where=t.invoice_state.in_([ 'none', 'waiting', 'exception'])), Index( t, - (t.shipment_state, Index.Equality()), + (t.shipment_state, Index.Equality(cardinality='low')), where=t.shipment_state.in_([ 'none', 'waiting', 'exception'])), }) diff --git a/modules/sale_amendment/sale.py b/modules/sale_amendment/sale.py index 7d031929a7..32b7de66ec 100644 --- a/modules/sale_amendment/sale.py +++ b/modules/sale_amendment/sale.py @@ -74,7 +74,7 @@ class Amendment(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state == 'draft')) cls._order = [ ('date', 'DESC'), diff --git a/modules/sale_blanket_agreement/sale.py b/modules/sale_blanket_agreement/sale.py index 4068fe0323..51788c3fcb 100644 --- a/modules/sale_blanket_agreement/sale.py +++ b/modules/sale_blanket_agreement/sale.py @@ -196,7 +196,7 @@ class BlanketAgreement(Workflow, ModelSQL, ModelView): cls._sql_indexes.update({ Index(t, (t.reference, Index.Similarity())), Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'running'])), }) diff --git a/modules/sale_complaint/complaint.py b/modules/sale_complaint/complaint.py index 62c2455fd0..a3a3af1ee5 100644 --- a/modules/sale_complaint/complaint.py +++ b/modules/sale_complaint/complaint.py @@ -141,7 +141,7 @@ class Complaint(Workflow, ModelSQL, ModelView): Index(t, (t.reference, Index.Similarity())), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'waiting', 'approved'])), }) cls._order.insert(0, ('date', 'DESC')) diff --git a/modules/sale_opportunity/opportunity.py b/modules/sale_opportunity/opportunity.py index 50d12466d8..7be6494547 100644 --- a/modules/sale_opportunity/opportunity.py +++ b/modules/sale_opportunity/opportunity.py @@ -159,13 +159,13 @@ class SaleOpportunity( t = cls.__table__() cls._sql_indexes.update({ Index(t, (t.reference, Index.Similarity())), - Index(t, (t.party, Index.Equality())), + Index(t, (t.party, Index.Range())), Index( t, (t.start_date, Index.Range(order='DESC')), (t.end_date, Index.Range(order='DESC'))), Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['lead', 'opportunity'])), }) cls._order.insert(0, ('start_date', 'DESC')) diff --git a/modules/sale_point/sale.py b/modules/sale_point/sale.py index 734d93581c..1e6f41e8a7 100644 --- a/modules/sale_point/sale.py +++ b/modules/sale_point/sale.py @@ -170,7 +170,7 @@ class POSSale(Workflow, ModelSQL, ModelView, TaxableMixin): t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['open', 'done']))) cls._transitions |= { ('open', 'done'), @@ -787,7 +787,10 @@ class POSCashSession(Workflow, ModelSQL, ModelView): 'sale_point.msg_cash_session_previous_unique'), ] cls._sql_indexes.add( - Index(t, (t.state, Index.Equality()), where=t.state == 'open')) + Index( + t, + (t.state, Index.Equality(cardinality='low')), + where=t.state == 'open')) cls._transitions |= { ('open', 'closed'), ('closed', 'open'), @@ -1232,7 +1235,10 @@ class POSCashTransfer(Workflow, ModelSQL, ModelView): super().__setup__() t = cls.__table__() cls._sql_indexes.add( - Index(t, (t.state, Index.Equality()), where=t.state == 'draft')) + Index( + t, + (t.state, Index.Equality(cardinality='low')), + where=t.state == 'draft')) cls._transitions |= { ('draft', 'posted'), } diff --git a/modules/sale_product_recommendation_association_rule/sale.py b/modules/sale_product_recommendation_association_rule/sale.py index 071eb0495d..bed1805c30 100644 --- a/modules/sale_product_recommendation_association_rule/sale.py +++ b/modules/sale_product_recommendation_association_rule/sale.py @@ -136,7 +136,7 @@ class ProductAssociationRule(ModelSQL, ModelView): (t.conviction, Index.Range(order='ASC'))), Index( t, - (t.id, Index.Range()), + (t.id, Index.Range(cardinality='high')), (t.lift, Index.Range(order='DESC'))), }) diff --git a/modules/sale_subscription/subscription.py b/modules/sale_subscription/subscription.py index c24466fef5..5e91563fa4 100644 --- a/modules/sale_subscription/subscription.py +++ b/modules/sale_subscription/subscription.py @@ -169,7 +169,7 @@ class Subscription(Workflow, ModelSQL, ModelView): Index(t, (t.reference, Index.Similarity())), Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'quotation', 'running'])), }) cls._order = [ diff --git a/modules/sale_supply_drop_shipment/stock.py b/modules/sale_supply_drop_shipment/stock.py index b4096af5b9..729c018014 100644 --- a/modules/sale_supply_drop_shipment/stock.py +++ b/modules/sale_supply_drop_shipment/stock.py @@ -166,7 +166,7 @@ class ShipmentDrop( t = cls.__table__() cls._sql_indexes.update({ Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'waiting', 'shipped'])), }) cls._order = [ diff --git a/modules/stock/inventory.py b/modules/stock/inventory.py index db30e9c878..1d4166dfa7 100644 --- a/modules/stock/inventory.py +++ b/modules/stock/inventory.py @@ -72,7 +72,10 @@ class Inventory(Workflow, ModelSQL, ModelView): super(Inventory, cls).__setup__() t = cls.__table__() cls._sql_indexes.add( - Index(t, (t.state, Index.Equality()), where=t.state == 'draft')) + Index( + t, + (t.state, Index.Equality(cardinality='low')), + where=t.state == 'draft')) cls._order.insert(0, ('date', 'DESC')) cls._transitions |= set(( ('draft', 'done'), diff --git a/modules/stock/location.py b/modules/stock/location.py index dce94e6126..4073884579 100644 --- a/modules/stock/location.py +++ b/modules/stock/location.py @@ -189,8 +189,8 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView): Index(t, (t.code, Index.Similarity())), Index( t, - (t.left, Index.Range()), - (t.right, Index.Range())), + (t.left, Index.Range(cardinality='high')), + (t.right, Index.Range(cardinality='high'))), }) cls._order.insert(0, ('name', 'ASC')) diff --git a/modules/stock/move.py b/modules/stock/move.py index 34fc50c10b..7c30233dba 100644 --- a/modules/stock/move.py +++ b/modules/stock/move.py @@ -404,7 +404,7 @@ class Move(Workflow, ModelSQL, ModelView): Index( t, (t.company, Index.Equality()), - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['staging', 'draft', 'assigned'])), }) cls._order[0] = ('id', 'DESC') diff --git a/modules/stock/period.py b/modules/stock/period.py index 76c77f59b0..1650e2a4cf 100644 --- a/modules/stock/period.py +++ b/modules/stock/period.py @@ -39,7 +39,7 @@ class Period(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.company, Index.Equality()), + (t.company, Index.Range()), (t.date, Index.Range(order='DESC')), where=t.state == 'closed')) cls._transitions |= set(( @@ -189,11 +189,11 @@ class Cache(ModelSQL, ModelView): cls._sql_indexes.update({ Index( t, - (t.period, Index.Equality()), + (t.period, Index.Range()), (t.location, Index.Range()), (t.product, Index.Range()), include=[t.internal_quantity]), Index( t, - (t.location, Index.Equality())), + (t.location, Index.Range())), }) diff --git a/modules/stock/product.py b/modules/stock/product.py index 2c06a2df30..a3877c4c9b 100644 --- a/modules/stock/product.py +++ b/modules/stock/product.py @@ -1290,9 +1290,9 @@ class CostPriceRevision(ModelSQL, ModifyCostPriceStart): cls._sql_indexes.add( Index( t, - (t.product, Index.Equality()), - (t.template, Index.Equality()), - (t.company, Index.Equality()))) + (t.product, Index.Range()), + (t.template, Index.Range()), + (t.company, Index.Range()))) cls._order.insert(0, ('date', 'DESC')) @classmethod diff --git a/modules/stock/shipment.py b/modules/stock/shipment.py index 31cbc11d79..4c91e6f44d 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -451,7 +451,7 @@ class ShipmentIn( cls._sql_indexes.update({ Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'received'])), }) cls._order = [ @@ -856,7 +856,7 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): cls._sql_indexes.update({ Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'waiting', 'assigned'])), }) cls._order = [ @@ -1275,7 +1275,7 @@ class ShipmentOut( cls._sql_indexes.update({ Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'draft', 'waiting', 'assigned', 'picked', 'packed', 'shipped'])), @@ -1981,7 +1981,7 @@ class ShipmentOutReturn( cls._sql_indexes.update({ Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['draft', 'received'])), }) cls._transitions |= set(( @@ -2460,7 +2460,7 @@ class ShipmentInternal( cls._sql_indexes.update({ Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_([ 'request', 'draft', 'waiting', 'assigned', 'shipped'])), diff --git a/modules/stock_forecast/forecast.py b/modules/stock_forecast/forecast.py index d4e2444323..08b145b167 100644 --- a/modules/stock_forecast/forecast.py +++ b/modules/stock_forecast/forecast.py @@ -71,7 +71,7 @@ class Forecast(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), (t.to_date, Index.Range()))) cls.create_date.select = True cls._order.insert(0, ('from_date', 'DESC')) diff --git a/modules/stock_lot/stock.py b/modules/stock_lot/stock.py index 559c9b26e3..57e375aa66 100644 --- a/modules/stock_lot/stock.py +++ b/modules/stock_lot/stock.py @@ -863,13 +863,13 @@ class PeriodCacheLot(ModelSQL, ModelView): cls._sql_indexes.update({ Index( t, - (t.period, Index.Equality()), - (t.product, Index.Equality()), - (t.lot, Index.Equality()), + (t.period, Index.Range()), + (t.product, Index.Range()), + (t.lot, Index.Range()), include=[t.internal_quantity]), Index( t, - (t.location, Index.Equality())), + (t.location, Index.Range())), }) diff --git a/modules/stock_quantity_early_planning/stock.py b/modules/stock_quantity_early_planning/stock.py index 74f564c7f1..0f989dff28 100644 --- a/modules/stock_quantity_early_planning/stock.py +++ b/modules/stock_quantity_early_planning/stock.py @@ -88,7 +88,7 @@ class QuantityEarlyPlan(Workflow, ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.state, Index.Equality()), + (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['open', 'processing']))) cls._transitions |= { ('open', 'processing'), diff --git a/modules/stock_quantity_issue/stock.py b/modules/stock_quantity_issue/stock.py index 4c5fdb7cc2..be5fe56212 100644 --- a/modules/stock_quantity_issue/stock.py +++ b/modules/stock_quantity_issue/stock.py @@ -76,7 +76,7 @@ class QuantityIssue( t = cls.__table__() cls._sql_indexes.add( Index( - t, (t.state, Index.Equality()), + t, (t.state, Index.Equality(cardinality='low')), where=t.state.in_(['open', 'processing']))) cls.priority.readonly = True cls._transitions |= { diff --git a/modules/timesheet/line.py b/modules/timesheet/line.py index 5e63752970..3c031abb71 100644 --- a/modules/timesheet/line.py +++ b/modules/timesheet/line.py @@ -80,23 +80,23 @@ class Line(ModelSQL, ModelView): cls._sql_indexes.update({ Index( t, - (t.date, Index.Equality()), - (t.company, Index.Equality()), - (t.employee, Index.Equality())), + (t.date, Index.Range()), + (t.company, Index.Range()), + (t.employee, Index.Range())), Index( t, (t.date, Index.Range()), - (t.employee, Index.Equality())), + (t.employee, Index.Range())), Index( t, - (Extract('YEAR', t.date), Index.Equality()), - (Extract('WEEK', t.date), Index.Equality()), - (t.employee, Index.Equality())), + (Extract('YEAR', t.date), Index.Range()), + (Extract('WEEK', t.date), Index.Range()), + (t.employee, Index.Range())), Index( t, - (Extract('YEAR', t.date), Index.Equality()), - (Extract('MONTH', t.date), Index.Equality()), - (t.employee, Index.Equality())), + (Extract('YEAR', t.date), Index.Range()), + (Extract('MONTH', t.date), Index.Range()), + (t.employee, Index.Range())), }) @staticmethod diff --git a/modules/timesheet_cost/company.py b/modules/timesheet_cost/company.py index bdaa306551..6aadb35e10 100644 --- a/modules/timesheet_cost/company.py +++ b/modules/timesheet_cost/company.py @@ -90,7 +90,7 @@ class EmployeeCostPrice(ModelSQL, ModelView): cls._sql_indexes.add( Index( t, - (t.employee, Index.Equality()), + (t.employee, Index.Range()), (t.date, Index.Range(order='ASC')))) cls._order.insert(0, ('date', 'DESC')) diff --git a/modules/web_user/user.py b/modules/web_user/user.py index e17736dadb..39f21ce86e 100644 --- a/modules/web_user/user.py +++ b/modules/web_user/user.py @@ -18,7 +18,7 @@ try: import html2text except ImportError: html2text = None -from sql import Literal +from sql import Literal, Null from sql.conditionals import Coalesce from sql.functions import CurrentTimestamp from sql.operators import Equal @@ -100,8 +100,12 @@ class User(avatar_mixin(100), DeactivableMixin, ModelSQL, ModelView): 'web_user.msg_user_email_unique'), ] cls._sql_indexes.update({ - Index(table, (table.email, Index.Equality())), - Index(table, (table.email_token, Index.Equality())), + Index( + table, (table.email, Index.Equality(cardinality='high'))), + Index( + table, + (table.email_token, Index.Equality(cardinality='high')), + where=table.email_token != Null), }) cls._buttons.update({ 'validate_email': { @@ -461,7 +465,7 @@ class UserSession(ModelSQL): table, (Coalesce(table.write_date, table.create_date), Index.Range())), - Index(table, (table.key, Index.Equality())), + Index(table, (table.key, Index.Equality(cardinality='high'))), }) @classmethod diff --git a/trytond/trytond/ir/error.py b/trytond/trytond/ir/error.py index 66cad04780..19e8f3c5b8 100644 --- a/trytond/trytond/ir/error.py +++ b/trytond/trytond/ir/error.py @@ -86,7 +86,7 @@ class Error(Workflow, ModelView, ModelSQL): cls._sql_indexes.add( Index( table, - (table.state, Index.Equality()), + (table.state, Index.Equality(cardinality='low')), where=table.state.in_(['open', 'processing']))) cls._transitions |= { ('open', 'processing'), diff --git a/trytond/trytond/ir/rule.py b/trytond/trytond/ir/rule.py index 6d670d872c..e8e05205d2 100644 --- a/trytond/trytond/ir/rule.py +++ b/trytond/trytond/ir/rule.py @@ -166,7 +166,7 @@ class Rule(ModelSQL, ModelView): table = cls.__table__() cls._sql_indexes.add( - Index(table, (table.rule_group, Index.Equality()))) + Index(table, (table.rule_group, Index.Range()))) @classmethod def validate_fields(cls, rules, field_names): diff --git a/trytond/trytond/ir/session.py b/trytond/trytond/ir/session.py index 2ba4fdf2f9..9da6eef4e2 100644 --- a/trytond/trytond/ir/session.py +++ b/trytond/trytond/ir/session.py @@ -28,13 +28,13 @@ class Session(ModelSQL): cls.__rpc__ = {} cls._sql_indexes.update({ Index(table, - (table.key, Index.Equality()), + (table.key, Index.Equality(cardinality='high')), (table.create_uid, Index.Equality())), Index(table, - (table.key, Index.Equality()), + (table.key, Index.Equality(cardinality='high')), (table.create_date, Index.Equality())), Index(table, - (table.key, Index.Equality()), + (table.key, Index.Equality(cardinality='high')), (table.write_date, Index.Equality())), }) diff --git a/trytond/trytond/ir/translation.py b/trytond/trytond/ir/translation.py index 51cffa9ed4..a5200682f6 100644 --- a/trytond/trytond/ir/translation.py +++ b/trytond/trytond/ir/translation.py @@ -98,24 +98,24 @@ class Translation( table, (Index.Unaccent(table.value), Index.Similarity())), Index( table, - (table.type, Index.Equality()), + (table.type, Index.Equality(cardinality='low')), (table.name, Index.Equality()), - (table.lang, Index.Equality()), + (table.lang, Index.Equality(cardinality='low')), (table.res_id, Index.Range()), - (table.fuzzy, Index.Equality()), + (table.fuzzy, Index.Equality(cardinality='low')), (Index.Unaccent(table.value), Index.Similarity())), Index( table, - (table.type, Index.Equality()), + (table.type, Index.Equality(cardinality='low')), (table.name, Index.Equality()), - (table.lang, Index.Equality()), - (table.fuzzy, Index.Equality())), + (table.lang, Index.Equality(cardinality='low')), + (table.fuzzy, Index.Equality(cardinality='low'))), Index( table, - (table.res_id, Index.Equality()), + (table.res_id, Index.Range()), (table.name, Index.Equality()), - (table.lang, Index.Equality()), - (table.type, Index.Equality())), + (table.lang, Index.Equality(cardinality='low')), + (table.type, Index.Equality(cardinality='low'))), }) @classmethod diff --git a/trytond/trytond/ir/trigger.py b/trytond/trytond/ir/trigger.py index ec4958081c..74427eee8a 100644 --- a/trytond/trytond/ir/trigger.py +++ b/trytond/trytond/ir/trigger.py @@ -312,5 +312,5 @@ class TriggerLog(ModelSQL): cls._sql_indexes.add( Index( table, - (table.trigger, Index.Equality()), + (table.trigger, Index.Range()), (table.record_id, Index.Range()))) diff --git a/trytond/trytond/ir/ui/view.py b/trytond/trytond/ir/ui/view.py index fef9a4cc82..5e84bd1b95 100644 --- a/trytond/trytond/ir/ui/view.py +++ b/trytond/trytond/ir/ui/view.py @@ -116,11 +116,11 @@ class View( cls._sql_indexes.update({ Index(table, (table.model, Index.Equality()), - (table.inherit, Index.Equality())), + (table.inherit, Index.Range())), Index( table, - (table.id, Index.Equality()), - (table.inherit, Index.Equality())), + (table.id, Index.Range()), + (table.inherit, Index.Range())), }) @staticmethod @@ -469,7 +469,7 @@ class ViewTreeWidth( cls._sql_indexes.add( Index( table, - (table.user, Index.Equality()), + (table.user, Index.Range()), (table.model, Index.Equality()), (table.field, Index.Equality()))) @@ -549,8 +549,8 @@ class ViewTreeOptional(ModelSQL, ModelView): cls._sql_indexes.add( Index( table, - (table.user, Index.Equality()), - (table.view_id, Index.Equality()))) + (table.user, Index.Range()), + (table.view_id, Index.Range()))) @classmethod def validate_fields(cls, records, fields_names): @@ -628,7 +628,7 @@ class ViewTreeState(ModelSQL, ModelView): cls._sql_indexes.add( Index( table, - (table.user, Index.Equality()), + (table.user, Index.Range()), (table.model, Index.Equality()), (table.child_name, Index.Equality()), (table.domain, Index.Equality()))) diff --git a/trytond/trytond/res/user.py b/trytond/trytond/res/user.py index 00f869f374..486603c8d2 100644 --- a/trytond/trytond/res/user.py +++ b/trytond/trytond/res/user.py @@ -1136,16 +1136,16 @@ class UserApplication(Workflow, ModelSQL, ModelView): table = cls.__table__() cls._sql_indexes.update({ - Index(table, (table.key, Index.Equality())), + Index(table, (table.key, Index.Equality(cardinality='high'))), Index( table, (table.user, Index.Equality()), - (table.state, Index.Equality())), + (table.state, Index.Equality(cardinality='low'))), Index( table, - (table.key, Index.Equality()), - (table.application, Index.Equality()), - (table.state, Index.Equality())), + (table.key, Index.Equality(cardinality='high')), + (table.application, Index.Equality(cardinality='low')), + (table.state, Index.Equality(cardinality='low'))), }) @classmethod