import { DatabaseClient } from '../../database/database-client.interface'; import { ICollectionStrategy, CollectionStrategyType, CollectionAggregationConfig, CollectionAggregationResult } from '../collection-strategy.interface'; import { QueryContext } from '../query-builder'; /** * Temp table-based collection strategy * * This strategy uses PostgreSQL temporary tables to store parent IDs, * then JOINs against them to aggregate related records. * * Benefits: * - Better performance for large datasets * - Indexed temp table JOIN can be faster than CTE * - More control over query plan * * Trade-offs: * - Requires two round trips (get parent IDs, then aggregate) * - Needs temp table management * - Transaction-scoped temp tables * * SQL Pattern: * ```sql * CREATE TEMP TABLE tmp_parent_ids_0 ( * id integer PRIMARY KEY * ) ON COMMIT DROP; * * INSERT INTO tmp_parent_ids_0 VALUES (1),(2),(3); * * SELECT * t.id as parent_id, * json_agg( * json_build_object('id', p.id, 'title', p.title) * ORDER BY p.views DESC * ) as data * FROM tmp_parent_ids_0 t * LEFT JOIN posts p ON p.user_id = t.id AND p.views > $1 * GROUP BY t.id; * ``` */ export declare class TempTableCollectionStrategy implements ICollectionStrategy { getType(): CollectionStrategyType; /** * Helper to rewrite the collection marker alias to the actual table name * For temp table strategy, we use the actual table name (no aliasing), so marker becomes table name */ private rewriteCollectionMarker; /** * Compose the trailing AND-clauses appended after the temp-table IN filter. * Combines the user's where clause (already rewritten for collection markers) * with any literal FK predicates declared on the navigation (e.g. SCD2 * `is_current = TRUE`). Returns "" or " AND ". Without this, the * temptable strategy leaks SCD2-closed target rows into the projection — the * exact QA_GO-429 Bug D symptom. */ private buildAdditionalWhere; requiresParentIds(): boolean; buildAggregation(config: CollectionAggregationConfig, context: QueryContext, client: DatabaseClient): Promise; /** * Build aggregation using multi-statement query (single round trip) * Supported by postgres.js using .simple() mode * * Uses the same server-side aggregation SQL as the legacy path (json_agg / * scalar aggregates) so both execution modes return identical values; only * the transport differs (one multi-statement round trip vs several queries). */ private buildAggregationMultiStatement; /** * Build aggregation using legacy approach (multiple queries) * Used for clients that don't support multi-statement queries */ private buildAggregationLegacy; /** * Renumber parameter placeholders in whereClause to start from $1 * This is needed because the whereClause is built with global param numbering, * but the legacy strategy executes it as a standalone query. */ private renumberWhereParams; /** * Build aggregation SQL based on aggregation type */ private buildAggregationSQLByType; /** * Build aggregation SQL with WHERE parameters interpolated * Used for multi-statement queries with .simple() mode * * For JSONB/array aggregations, this returns a simple SELECT without aggregation * so we can group in JavaScript (much faster than json_agg) */ private buildAggregationSQLWithInterpolatedParams; /** * Safely escape a value for SQL interpolation * Used only in multi-statement queries with .simple() mode */ private escapeValue; /** * Build aggregation for when there are no parent IDs */ private buildEmptyAggregation; /** * Build JSONB aggregation using temp table * * When LIMIT/OFFSET is specified, uses ROW_NUMBER() window function to correctly * apply pagination per parent row (not globally). */ private buildJsonbAggregationSQL; /** * Build JSONB aggregation with ROW_NUMBER() for per-parent LIMIT/OFFSET */ private buildJsonbAggregationSQLWithRowNumber; /** * Build array aggregation using temp table * * When LIMIT/OFFSET is specified, uses ROW_NUMBER() window function to correctly * apply pagination per parent row (not globally). */ private buildArrayAggregationSQL; /** * Build array aggregation with ROW_NUMBER() for per-parent LIMIT/OFFSET */ private buildArrayAggregationSQLWithRowNumber; /** * Build scalar aggregation using temp table */ private buildScalarAggregationSQL; /** * Build EXISTS aggregation using temp table * Returns true for each parent that has at least one child row */ private buildExistsAggregationSQL; } //# sourceMappingURL=temptable-collection-strategy.d.ts.map