Repository navigation
TUR-279: MLIR: unwind a list built per row without building a whole chunk of lists - #1184
Conversation
|
Note AI-generated summary. SummaryAn UNWIND over a list built per row laid out the lists of the whole 64Ki-row chunk before the first row was unwound. b69d60f fixed this for a bare
d547734: build no list UNWIND [x IN xs WHERE p | f] AS y
- db.unwind(db.list_comprehension(xs) { db.filter(p); yield f })
+ db.unwind(xs) db.filter(p, {x, rows in flight...}) f # unnest_unwind_comprehension, first pass
UNWIND reverse(range(a, b, s)[i..j]) AS x
- db.unwind(db.reverse(db.list_slice(db.range(a, b, s), i, j)))
+ db.unwind_range(a, b, s, from i, to j, {...}) reversed # fuse_unwind_range
The range cursor ( 408bae5: compute the list a few rows at a timeA new last pass, %i = db.unwind_range(%c1, %c65536, %c1, {}) : ...
%j, %iOut = db.unwind_computed({%i}) ({
^bb0(%iRow: !db.column<!storage.nullable<i64>>):
%end = db.add %iRow, %c999 : ...
%xs = db.range(%iRow, %end) : ...
%ys = db.list_comprehension(%xs, {}) ({ ... }) : ...
%r = db.reverse(%ys) : ...
db.unwind_yield %r : !db.column<none>
}) : ...The pass leaves an unwind alone when its source is a constant or a stored property read, because no list is built for those. A run holds about one chunk of elements, so peak memory is one chunk plus the longest single list. For short lists the run grows back to the whole chunk. c287b92: read a row count off the cheapest columnCodegen anchors every read that needs only a row count on whatever column is in scope. Three ops read a column that way: %j, %l2 = db.unwind(%l, {%l})
-%n = db.count(%l2) rows
+%n = db.count(%j) rows # anchor_row_countsA new pass,
The pass runs just before the first Evidence
Merge DangerDoor: two-way The rewrites are db passes and the op changes are additive. Reverting a commit restores the lists it stopped building. Blast Radius: queries Every query now runs three more passes. Every UNWIND whose list is computed from the row now goes through |
Unwind a list built per row without building the lists of a whole chunk.