Correlated toArray over a distinct derived query drops children from earlier parents
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 58/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- database
Línea de trabajo
Start by running the provided reproduction with Bun and the listed package versions, then trace how .distinct() results are consumed by a correlated toArray() query. Compare the two loop iterations and check which parent’s children disappear. Done when both iterations return the expected rows for both parents, with a regression test covering distinct derived queries used as nested sources.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
A correlated toArray() loses rows from an earlier parent when its source is a derived query with .distinct(). The same query without .distinct() returns all expected rows, even though the input contains no duplicates.
Reproduced with @tanstack/[email protected] / @tanstack/[email protected], Bun 1.4.4, macOS. No React rendering or external sync service is needed.
Run this as bun repro.mjs in a project with @tanstack/[email protected] installed:
import { createCollection, Query, eq, toArray, queryOnce } from '@tanstack/react-db';
function coll(id, rows) {
return createCollection({
id, getKey: r => r.id, startSync: true,
sync: { sync: ({ begin, write, commit, markReady }) => {
begin();
for (const value of rows) write({ type: 'insert', value });
commit();
markReady();
} },
});
}
const groups = coll('groups', [{ id: 'a' }, { id: 'b' }]);
const items = coll('items', [
{ id: 'a1', group: 'a', value: '1' },
{ id: 'a2', group: 'a', value: '2' },
{ id: 'b1', group: 'b', value: '1' },
{ id: 'b2', group: 'b', value: '2' },
]);
for (const dedup of [false, true]) {
let derived = new Query().from({ row: items })
.select(({ row }) => ({ group: row.group, value: row.value }));
if (dedup) derived = derived.distinct();
const query = new Query().from({ g: groups }).select(({ g }) => ({
id: g.id,
items: toArray(new Query().from({ item: derived })
.where(({ item }) => eq(item.group, g.id))
.select(({ item }) => ({ value: item.value }))),
}));
console.log(dedup, JSON.stringify((await queryOnce({ query }))
.map(({ id, items }) => ({ id, items }))));
}
Expected for both iterations:
[{"id":"a","items":[{"value":"1"},{"value":"2"}]},{"id":"b","items":[{"value":"1"},{"value":"2"}]}]
Actual with dedup=true:
[{"id":"a","items":[]},{"id":"b","items":[{"value":"1"},{"value":"2"}]}]
The derived rows differ by group, so they should remain distinct. This silently omits children when multiple parents have equal projected child values. Materializing the distinct derived query into a live-query collection before using it as the nested source avoids the omission in testing, but requires a separate collection lifecycle.
I checked #1709 (join scan cost) and #1975 (reused aliases). This reproduction has no join and uses different aliases, so it appears to be a separate correctness issue.
- Lenguaje dominante
- TypeScript
- Estrellas
- 4k
- Forks
- 277
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 213
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/db
-
`Collection.currentStateAsChanges` JSDoc examples don’t match `CurrentStateAsChangesOptions`Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
OfflineExecutor.dispose() never settles pendingTransactionPromisesPosiblemente ocupada @Claire-ovo la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
TanStack/db#2254 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeoutPosiblemente ocupada @jp-knj la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/db
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
marmelab/react-admin#11431 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
db-ux-design-system/core-web#8655 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
stripe/react-stripe-js#728 ·
-
[Upload Grade C dataset] the pop-up changes it's size while uploading the document => Jumping effectAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
epam/statgpt-admin-frontend#305 ·
Los mantenedores suelen responder en 1 día