Skip to content

Commit 53d79bb

Browse files
authored
fix(query-orchestrator): Table used cache should not be used for unions (#10192)
We don't need to cache them or mark as used in cache store, because it's single tables. Caching such keys result in huge memory usage, we can call it as memory leak.
1 parent 2986f19 commit 53d79bb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,15 @@ export class PreAggregationPartitionRangeLoader {
295295
const unionTargetTableName = allTableTargetNames
296296
.map(targetTableName => `SELECT * FROM ${targetTableName}${emptyResult ? ' WHERE 1 = 0' : ''}`)
297297
.join(' UNION ALL ');
298+
298299
return {
299300
targetTableName: allTableTargetNames.length === 1 && !emptyResult ? allTableTargetNames[0] : `(${unionTargetTableName})`,
300301
refreshKeyValues: loadResults.map(t => t.refreshKeyValues),
301302
lastUpdatedAt,
302303
buildRangeEnd: !emptyResult && loadResults.length && loadResults[loadResults.length - 1].buildRangeEnd,
303304
lambdaTable,
304305
rollupLambdaId: this.preAggregation.rollupLambdaId,
306+
isMultiTableUnion: allTableTargetNames.length > 1,
305307
};
306308
} else {
307309
return new PreAggregationLoader(

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export type LoadPreAggregationResult = {
142142
queryKey?: any[];
143143
rollupLambdaId?: string;
144144
partitionRange?: QueryDateRange;
145+
isMultiTableUnion?: boolean;
145146
};
146147

147148
export type PreAggregationTableToTempTable = [string, LoadPreAggregationResult];
@@ -515,7 +516,9 @@ export class PreAggregations {
515516
...loadResult,
516517
type: p.type,
517518
};
518-
await this.addTableUsed(usedPreAggregation.targetTableName);
519+
if (!usedPreAggregation.isMultiTableUnion) {
520+
await this.addTableUsed(usedPreAggregation.targetTableName);
521+
}
519522

520523
if (i === preAggregations.length - 1 && queryBody.values) {
521524
queryParamsReplacement = await loader.replaceQueryBuildRangeParams(

0 commit comments

Comments
 (0)