RunQuery: add SkipTotalRowCount so MaxRows does not run the whole query a second time for its count

Aperta
#6,880 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
graphql, sql, typescript
Ambito
api, backend, database

Direzione di ricerca

Start with RunViewParams.SkipTotalRowCount to see the existing pattern, then read GenericDatabaseProvider.ts around the parallel data/count block (~L7838) and countAdhocRows (~L8074). Trace RunQueryParams through the saved-query and ad-hoc ExecuteFromSpec paths, and the GraphQL inputs GetQueryData, GetQueryDataByName and the ad-hoc test resolvers. Done means both paths page without issuing CountSQL when the flag is true, pass the flag from GraphQL, and preserve current behavior by default.

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

Descrizione

Summary

RunView can skip its total-row count (SkipTotalRowCount, in RunViewParams since 6.2.2), but RunQuery cannot. Whenever a RunQuery call sets MaxRows, the provider pages the query and runs the whole query a second time as a COUNT(*), in parallel with the page:

  • saved queries: GenericDatabaseProvider.ts ~L7838 on next ("Execute data + count queries in parallel"), the same code in 6.1.6 and 6.2.2;
  • ad-hoc SQL (ExecuteFromSpec / RunQuery with SQL): countAdhocRows(rendered.PagingResult?.CountSQL ...) ~L8074.

So MaxRows limits the rows returned but roughly doubles the database work for a heavy query, and there is no way to opt out. A caller that only wants a few rows (a sample, a smoke test, a preview) has to choose between:

  1. No MaxRows: the full result is fetched and serialized. A saved query over an 8M-row table made MJAPI fail with RangeError: Invalid string length in RunQueryResolver.GetQueryData (JSON.stringify).
  2. MaxRows: the full query runs twice. An aggregate that takes 13-49 s on its own hits a 30 s requestTimeout because the parallel COUNT(*) competes with it on the same database.

We hit both from Skip on a client database (Azure SQL serverless, 4 vCores): Skip runs every query it saves once, with test parameters, to confirm it executes and to cache sample rows.

Proposal

Add SkipTotalRowCount?: boolean to RunQueryParams, mirroring RunViewParams:

  • when true with MaxRows, page the query (OFFSET ... FETCH / LIMIT) but do not run the CountSQL; return TotalRowCount as the rows returned (or leave it undefined), as RunView does;
  • apply it to both the saved-query path and the ad-hoc SQL path;
  • expose it on the GraphQL query inputs (GetQueryData, GetQueryDataByName, and the ad-hoc test resolvers) so remote callers can pass it;
  • default false, so existing callers that rely on TotalRowCount keep it.

Related

  • #6000 (RunView with MaxRows: 1 and TotalRowCount): the RunView side of the same trade-off.
Lingua principale
TSQL
Stelle
32
Fork
7
Merge medio
1g 16h
PR unite (30g)
504

Preparare l'ambiente

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 MemberJunction/MJ

Tutte le issue di MemberJunction/MJ

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.