Refine index definition

- Set low and high cardinality to index usage
- Use Range usage for numerical expression instead of Equality
This commit is contained in:
Cédric Krier committed 2024-07-27 18:36:14 +02:00
1 parent 234daa0f99
commit a2dfc4455b
64 files changed
+171 -149

No files matched your search

+5 -5
View File
@@ -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):
+13 -13
View File
@@ -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),
})
+1 -1
View File
@@ -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'),
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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({
+1 -1
View File
@@ -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
+5 -4
View File
@@ -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),
})
+1 -1
View File
@@ -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',
+1 -1
View File
@@ -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'))
+1 -1
View File
@@ -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')
+2 -2
View File
@@ -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'),
+1 -1
View File
@@ -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')
+2 -2
View File
@@ -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')
+1 -1
View File
@@ -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'),
+2 -2
View File
@@ -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(
+4 -1
View File
@@ -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'),
@@ -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'),
+1 -1
View File
@@ -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'))
+1 -1
View File
@@ -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'),
+2 -1
View File
@@ -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):
+1 -1
View File
@@ -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'))
@@ -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'),
+3 -3
View File
@@ -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'),
+2 -2
View File
@@ -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())),
})
+2 -2
View File
@@ -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'))
+2 -2
View File
@@ -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):
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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'])),
+2 -2
View File
@@ -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'),
+4 -4
View File
@@ -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'])),
})
+1 -1
View File
@@ -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'),
@@ -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 = [
+1 -1
View File
@@ -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({
@@ -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((
+1 -1
View File
@@ -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((
+4 -4
View File
@@ -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'])),
})
+1 -1
View File
@@ -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'),
+1 -1
View File
@@ -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'])),
})
+1 -1
View File
@@ -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'))
+2 -2
View File
@@ -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'))
+9 -3
View File
@@ -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'),
}
@@ -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'))),
})
+1 -1
View File
@@ -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 = [
+1 -1
View File
@@ -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 = [
+4 -1
View File
@@ -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'),
+2 -2
View File
@@ -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'))
+1 -1
View File
@@ -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')
+3 -3
View File
@@ -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())),
})
+3 -3
View File
@@ -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
+5 -5
View File
@@ -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'])),
+1 -1
View File
@@ -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'))
+4 -4
View File
@@ -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())),
})
@@ -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'),
+1 -1
View File
@@ -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 |= {
+10 -10
View File
@@ -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
+1 -1
View File
@@ -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'))
+8 -4
View File
@@ -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
+1 -1
View File
@@ -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'),
+1 -1
View File
@@ -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):
+3 -3
View File
@@ -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())),
})
+9 -9
View File
@@ -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
+1 -1
View File
@@ -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())))
+7 -7
View File
@@ -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())))
+5 -5
View File
@@ -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