Send a value used several times in one query to the database once

Aperta
#1,916 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, postgresql, sql
Ambito
backend, database

Direzione di ricerca

Start by reading the query parameter handling for large values and how it differs across PostgreSQL, MSSQL, and EXTERNAL SQL calls; the issue does not name source files or tests. Trace how repeated uses of one large parameter are represented in a query, then add coverage for the PostgreSQL case and confirm MSSQL and EXTERNAL SQL behavior remains as described. Done means PostgreSQL sends the value once per query while other uses refer to it.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

Some values reach a query as parameters rather than as text written into it: a string longer than 1000 characters or with a quote or a backslash in it, and a file. Such a value - for example the value of a LOCAL property without parameters, used in a query - was sent to the database once for every place where the query uses it. Formulas with IF multiply those places: while the result stays below limitPullCasesComplexity, a formula of N IF operands is built for every combination of their branches (see #1903), so a value used once in each operand appears in the query N * 2^(N-1) times.

big = DATA LOCAL TEXT (); // 800 000 characters
firstChar (TEXT s, INTEGER n) = FORMULA TEXT 'substr($1, $2, 1)';

result() <- GROUP CONCAT (IF mod(INTEGER i, 2) = 0 THEN firstChar(big(), 1) ELSE 'y')
        + (IF mod(i, 3) = 0 THEN firstChar(big(), 2) ELSE 'y')
        + (IF mod(i, 5) = 0 THEN firstChar(big(), 3) ELSE 'y') IF iterate(i, 1, 2400), '' ORDER i;

Here the query uses big() 12 times, so about 10 MB went to the database for one statement. On PostgreSQL such a value now goes once per query, and its other uses refer to it. On MSSQL, and in EXTERNAL SQL calls, every use still sends a value of its own. Only large values are affected noticeably: a copy of a short one costs next to nothing.

Without the change, the copies can be avoided by computing what is needed from the large value into a LOCAL first, as the precomputed variant in #1903 does.

Reason

Found while fixing #1903: with the large value of that issue's example passed as a parameter instead of a literal, its query still carried tens of MB - a copy of the value for every use -, and its first run took long enough to be cancelled by a timeout and run again. With the value sent once, repeated runs of the IF variant of that example went from 236 / 241 ms to 162 / 123 ms.

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lsfusion/platform

Tutte le issue di lsfusion/platform

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.