Use a composite index that starts with a nullable grouping property for ordered groupings on PostgreSQL
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 49/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- java, postgresql
- Ambito
- databases, performance
Direzione di ricerca
Start by tracing how the platform translates ordered GROUP expressions and declared composite indexes into PostgreSQL queries; the issue gives a reproducible example and reports the plan on PostgreSQL 18.1. Compare the all-groups query with the single-group case fixed by #1727, then verify that PostgreSQL can use the declared index without a separate sort for the all-groups query.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
An order-dependent grouping with a BY block (GROUP LAST ... ORDER ... BY, and the other grouping types that take ORDER) that is computed for all groups at once cannot get the ordering it needs from the composite index declared for it — grouping property, ordering property, object — when the grouping property is stored in a nullable column, which is every property that is not a key of its table.
CLASS Rec;
grp = DATA LONG (Rec);
ord = DATA DATE (Rec);
val = DATA NUMERIC[10,2] (Rec);
INDEX grp(Rec r), ord(r), r;
lastVal (LONG g) = GROUP LAST val(Rec r) ORDER ord(r), r BY grp(r);
On PostgreSQL 18.1 the query that reads lastVal for every group at once — an assignment or an export over all objects, a recalculation of a materialized grouping — is planned as a sequential scan of the table followed by a sort of all its rows; with 2 000 000 rows in 50 000 groups that is an external merge sort of 82 MB. No plan reads the index above in order: the sort stays in the plan with sorting disabled in the planner.
When the value is read for one group, the same index is used (an index scan backward with LIMIT 1), which is what #1727 fixed.
Reason
The index is declared exactly for this grouping, by the rule for composite indexes (the property the rows are selected by first, the ordering one after it), and it works for one group, so nothing tells the developer that the query over all groups cannot use it. On large tables the sort can spill to disk. One verified workaround is an index created in the database by hand, with the default placement of NULL values on the grouping column, which the platform knows nothing about.
Fix
PostgreSQL can satisfy the ordering of a grouping with an ordered aggregate over all groups from the index (grouping property, ordering property, object) declared in the logic, without a separate sort, as it can with the manually created index.
- Lingua principale
- Java
- Stelle
- 214
- Fork
- 46
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di lsfusion/platform
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
Tutte le issue di lsfusion/platform
Issue simili
-
account assessment course feature lecture
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
app:learninggoalhub enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
PropertyResolver fails on JDK classes with a non-public field named like the propertyForse già presa @vaibhavgupta443 l’ha presa oggi. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
apache/wicket#1991 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100