rawsql-ts 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +2 -2
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js +3 -71
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js.map +1 -1
- package/dist/esm/transformers/PredicateExpressionUtils.d.ts +16 -0
- package/dist/esm/transformers/PredicateExpressionUtils.js +74 -0
- package/dist/esm/transformers/PredicateExpressionUtils.js.map +1 -0
- package/dist/esm/transformers/PredicateReachabilityAnalyzer.d.ts +88 -0
- package/dist/esm/transformers/PredicateReachabilityAnalyzer.js +495 -0
- package/dist/esm/transformers/PredicateReachabilityAnalyzer.js.map +1 -0
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.d.ts +2 -0
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js +156 -162
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +1 -0
- package/dist/src/transformers/PredicateExpressionUtils.d.ts +16 -0
- package/dist/src/transformers/PredicateReachabilityAnalyzer.d.ts +88 -0
- package/dist/src/transformers/StaticPredicatePlacementOptimizer.d.ts +2 -0
- package/dist/transformers/ParameterConditionPlacementOptimizer.js +38 -106
- package/dist/transformers/ParameterConditionPlacementOptimizer.js.map +1 -1
- package/dist/transformers/PredicateExpressionUtils.js +88 -0
- package/dist/transformers/PredicateExpressionUtils.js.map +1 -0
- package/dist/transformers/PredicateReachabilityAnalyzer.js +508 -0
- package/dist/transformers/PredicateReachabilityAnalyzer.js.map +1 -0
- package/dist/transformers/StaticPredicatePlacementOptimizer.js +190 -196
- package/dist/transformers/StaticPredicatePlacementOptimizer.js.map +1 -1
- package/dist/tsconfig.browser.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -80,6 +80,7 @@ export * from './transformers/SSSQLFilterBuilder';
|
|
|
80
80
|
export type { FormattableSqlComponent, SqlComponentFormatter, SqlComponentFormatOptions } from './transformers/SqlComponentFormatter';
|
|
81
81
|
export * from './transformers/ConditionOptimization';
|
|
82
82
|
export * from './transformers/ParameterConditionPlacementOptimizer';
|
|
83
|
+
export * from './transformers/PredicateReachabilityAnalyzer';
|
|
83
84
|
export * from './transformers/StaticPredicatePlacementOptimizer';
|
|
84
85
|
export * from './transformers/PruneOptionalConditionBranches';
|
|
85
86
|
export { SchemaInfo, optimizeUnusedLeftJoins, optimizeUnusedLeftJoinsToFixedPoint, optimizeUnusedCtes, optimizeUnusedCtesToFixedPoint } from './transformers/OptimizeUnusedLeftJoins';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WhereClause } from "../models/Clause";
|
|
2
|
+
import { BinaryExpression, ColumnReference, ValueComponent } from "../models/ValueComponent";
|
|
3
|
+
import { SqlComponentFormatOptions } from "./SqlComponentFormatter";
|
|
4
|
+
export declare const normalizeIdentifier: (value: string) => string;
|
|
5
|
+
export declare const identifiersEqual: (left: string, right: string) => boolean;
|
|
6
|
+
export declare const unwrapParens: (expression: ValueComponent) => ValueComponent;
|
|
7
|
+
export declare const isBinaryOperator: (expression: ValueComponent, operator: string) => expression is BinaryExpression;
|
|
8
|
+
export declare const collectTopLevelAndTerms: (expression: ValueComponent) => ValueComponent[];
|
|
9
|
+
export declare const rebuildWhereWithoutTerms: (query: {
|
|
10
|
+
whereClause: WhereClause | null;
|
|
11
|
+
}, termsToRemove: ReadonlySet<ValueComponent>) => void;
|
|
12
|
+
export declare const cloneValueComponent: (expression: ValueComponent, options: SqlComponentFormatOptions) => ValueComponent;
|
|
13
|
+
export declare const cloneColumnReference: (reference: ColumnReference) => ColumnReference;
|
|
14
|
+
export declare const columnReferenceText: (reference: ColumnReference) => string;
|
|
15
|
+
export declare const sameColumnReference: (left: ColumnReference, right: ColumnReference) => boolean;
|
|
16
|
+
export declare const appendUnique: <T>(items: T[], value: T) => void;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
|
2
|
+
import { SqlComponentFormatOptions } from "./SqlComponentFormatter";
|
|
3
|
+
export type PredicateReachabilityInput = string | SelectQuery | SimpleSelectQuery;
|
|
4
|
+
export interface PredicateReachabilityOptions extends SqlComponentFormatOptions {
|
|
5
|
+
cloneInput?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PredicateReachabilityWarning {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
detail?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface PredicateReachabilityError {
|
|
13
|
+
code: string;
|
|
14
|
+
message: string;
|
|
15
|
+
detail?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export type PredicateReachabilityMode = "rewrite_safe" | "debug_only";
|
|
18
|
+
export type PredicateReachabilityRelation = "origin" | "direct_output" | "join_equivalence";
|
|
19
|
+
export type PredicateReachabilityProbeKind = "count" | "sample";
|
|
20
|
+
export interface PredicateReachabilityScopeTarget {
|
|
21
|
+
kind: "scope" | "cte" | "table" | "subquery" | "source";
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
export interface PredicateReachabilityTarget {
|
|
25
|
+
scopeId: string;
|
|
26
|
+
relation: PredicateReachabilityRelation;
|
|
27
|
+
mode: PredicateReachabilityMode;
|
|
28
|
+
predicateSql: string;
|
|
29
|
+
via?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface PredicateReachabilityBlocked {
|
|
32
|
+
scopeId: string;
|
|
33
|
+
relation: PredicateReachabilityRelation;
|
|
34
|
+
code: string;
|
|
35
|
+
reason: string;
|
|
36
|
+
via?: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
export interface PredicateReachabilityProbeTarget {
|
|
39
|
+
scopeId: string;
|
|
40
|
+
relation: PredicateReachabilityRelation;
|
|
41
|
+
mode: PredicateReachabilityMode;
|
|
42
|
+
predicateSql: string;
|
|
43
|
+
target: PredicateReachabilityScopeTarget;
|
|
44
|
+
probeKinds: readonly PredicateReachabilityProbeKind[];
|
|
45
|
+
caution?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface PredicateReachabilityPredicate {
|
|
48
|
+
predicateSql: string;
|
|
49
|
+
originScopeId: string;
|
|
50
|
+
columnReferences: readonly string[];
|
|
51
|
+
reaches: readonly PredicateReachabilityTarget[];
|
|
52
|
+
blocked: readonly PredicateReachabilityBlocked[];
|
|
53
|
+
probeTargets: readonly PredicateReachabilityProbeTarget[];
|
|
54
|
+
}
|
|
55
|
+
export interface PredicateReachabilitySafety {
|
|
56
|
+
mode: "debug_only";
|
|
57
|
+
sqlRewritten: false;
|
|
58
|
+
}
|
|
59
|
+
export interface PredicateReachabilityResult {
|
|
60
|
+
ok: boolean;
|
|
61
|
+
query: SelectQuery | null;
|
|
62
|
+
predicates: readonly PredicateReachabilityPredicate[];
|
|
63
|
+
warnings: readonly PredicateReachabilityWarning[];
|
|
64
|
+
errors: readonly PredicateReachabilityError[];
|
|
65
|
+
safety: PredicateReachabilitySafety;
|
|
66
|
+
}
|
|
67
|
+
export declare class PredicateReachabilityAnalyzer {
|
|
68
|
+
analyze(input: PredicateReachabilityInput, options?: PredicateReachabilityOptions): PredicateReachabilityResult;
|
|
69
|
+
private analyzeScope;
|
|
70
|
+
private buildProbeTargets;
|
|
71
|
+
private describeScopeTarget;
|
|
72
|
+
private resolveDirectOutputReach;
|
|
73
|
+
private resolveJoinEquivalenceReach;
|
|
74
|
+
private collectJoinEqualities;
|
|
75
|
+
private resolveSourceQuery;
|
|
76
|
+
private resolveDirectOutputColumn;
|
|
77
|
+
private collectSelectOutputs;
|
|
78
|
+
private findCte;
|
|
79
|
+
private resolveSourceBinding;
|
|
80
|
+
private resolveSourceBindingFromList;
|
|
81
|
+
private getSourceBindings;
|
|
82
|
+
private scopeIdForBinding;
|
|
83
|
+
private isInnerJoin;
|
|
84
|
+
private rebasePredicate;
|
|
85
|
+
private collectOuterColumnReferences;
|
|
86
|
+
private buildResult;
|
|
87
|
+
}
|
|
88
|
+
export declare const analyzePredicateReachability: (input: PredicateReachabilityInput, options?: PredicateReachabilityOptions) => PredicateReachabilityResult;
|
|
@@ -60,6 +60,7 @@ export interface StaticPredicatePlacementResult {
|
|
|
60
60
|
}
|
|
61
61
|
export declare class StaticPredicatePlacementOptimizer {
|
|
62
62
|
plan(input: StaticPredicatePlacementInput, options?: StaticPredicatePlacementOptions): StaticPredicatePlacementResult;
|
|
63
|
+
private placePredicatesInScopes;
|
|
63
64
|
optimize(input: StaticPredicatePlacementInput, options?: StaticPredicatePlacementOptions): StaticPredicatePlacementResult;
|
|
64
65
|
private parseInput;
|
|
65
66
|
private analyzeCandidate;
|
|
@@ -68,6 +69,7 @@ export declare class StaticPredicatePlacementOptimizer {
|
|
|
68
69
|
private resolveTarget;
|
|
69
70
|
private findRootQueryBoundary;
|
|
70
71
|
private resolveTargetPlacement;
|
|
72
|
+
private findNullableSideBoundaryForTargetColumns;
|
|
71
73
|
private resolveSourceBinding;
|
|
72
74
|
private resolveUpstreamQuery;
|
|
73
75
|
private resolveUnionTarget;
|
|
@@ -5,80 +5,12 @@ const Clause_1 = require("../models/Clause");
|
|
|
5
5
|
const SelectQuery_1 = require("../models/SelectQuery");
|
|
6
6
|
const ValueComponent_1 = require("../models/ValueComponent");
|
|
7
7
|
const SelectQueryParser_1 = require("../parsers/SelectQueryParser");
|
|
8
|
-
const ValueParser_1 = require("../parsers/ValueParser");
|
|
9
8
|
const SqlComponentFormatter_1 = require("./SqlComponentFormatter");
|
|
10
9
|
const SelectOutputCollector_1 = require("./SelectOutputCollector");
|
|
11
10
|
const TopLevelAndConditionDeduper_1 = require("./TopLevelAndConditionDeduper");
|
|
11
|
+
const PredicateExpressionUtils_1 = require("./PredicateExpressionUtils");
|
|
12
12
|
const SUPPORTED_OPERATORS = new Set(["=", "<>", "!=", "<", "<=", ">", ">=", "like", "ilike", "in"]);
|
|
13
13
|
const VOLATILE_OR_UNSUPPORTED_FUNCTION_REASON = "Condition contains a function call; volatile and expression predicates are not moved in the safe-only implementation.";
|
|
14
|
-
const normalizeIdentifier = (value) => value.trim().toLowerCase();
|
|
15
|
-
const isCaseSensitiveIdentifier = (value) => /[A-Z]/.test(value.trim());
|
|
16
|
-
const identifiersEqual = (left, right) => {
|
|
17
|
-
const trimmedLeft = left.trim();
|
|
18
|
-
const trimmedRight = right.trim();
|
|
19
|
-
return isCaseSensitiveIdentifier(trimmedLeft) || isCaseSensitiveIdentifier(trimmedRight)
|
|
20
|
-
? trimmedLeft === trimmedRight
|
|
21
|
-
: trimmedLeft.toLowerCase() === trimmedRight.toLowerCase();
|
|
22
|
-
};
|
|
23
|
-
const unwrapParens = (expression) => {
|
|
24
|
-
let candidate = expression;
|
|
25
|
-
while (candidate instanceof ValueComponent_1.ParenExpression) {
|
|
26
|
-
candidate = candidate.expression;
|
|
27
|
-
}
|
|
28
|
-
return candidate;
|
|
29
|
-
};
|
|
30
|
-
const isBinaryOperator = (expression, operator) => {
|
|
31
|
-
const candidate = unwrapParens(expression);
|
|
32
|
-
return candidate instanceof ValueComponent_1.BinaryExpression
|
|
33
|
-
&& candidate.operator.value.trim().toLowerCase() === operator;
|
|
34
|
-
};
|
|
35
|
-
const collectTopLevelAndTerms = (expression) => {
|
|
36
|
-
const candidate = unwrapParens(expression);
|
|
37
|
-
if (!isBinaryOperator(candidate, "and")) {
|
|
38
|
-
return [expression];
|
|
39
|
-
}
|
|
40
|
-
return [
|
|
41
|
-
...collectTopLevelAndTerms(candidate.left),
|
|
42
|
-
...collectTopLevelAndTerms(candidate.right)
|
|
43
|
-
];
|
|
44
|
-
};
|
|
45
|
-
const rebuildWhereWithoutTerms = (query, termsToRemove) => {
|
|
46
|
-
if (!query.whereClause || termsToRemove.size === 0) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const remaining = collectTopLevelAndTerms(query.whereClause.condition)
|
|
50
|
-
.filter(term => !termsToRemove.has(term));
|
|
51
|
-
if (remaining.length === 0) {
|
|
52
|
-
query.whereClause = null;
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
let rebuilt = remaining[0];
|
|
56
|
-
for (let index = 1; index < remaining.length; index += 1) {
|
|
57
|
-
rebuilt = new ValueComponent_1.BinaryExpression(rebuilt, "and", remaining[index]);
|
|
58
|
-
}
|
|
59
|
-
query.whereClause = new Clause_1.WhereClause(rebuilt);
|
|
60
|
-
};
|
|
61
|
-
const cloneValueComponent = (expression, options) => {
|
|
62
|
-
return ValueParser_1.ValueParser.parse((0, SqlComponentFormatter_1.formatSqlComponent)(expression, options));
|
|
63
|
-
};
|
|
64
|
-
const cloneColumnReference = (reference) => {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
const namespaces = (_b = (_a = reference.namespaces) === null || _a === void 0 ? void 0 : _a.map(namespace => namespace.name)) !== null && _b !== void 0 ? _b : null;
|
|
67
|
-
return new ValueComponent_1.ColumnReference(namespaces, reference.column.name);
|
|
68
|
-
};
|
|
69
|
-
const columnReferenceText = (reference) => {
|
|
70
|
-
const namespace = reference.getNamespace();
|
|
71
|
-
return namespace ? `${namespace}.${reference.column.name}` : reference.column.name;
|
|
72
|
-
};
|
|
73
|
-
const sameColumnReference = (left, right) => {
|
|
74
|
-
return identifiersEqual(left.column.name, right.column.name)
|
|
75
|
-
&& identifiersEqual(left.getNamespace(), right.getNamespace());
|
|
76
|
-
};
|
|
77
|
-
const appendUnique = (items, value) => {
|
|
78
|
-
if (!items.includes(value)) {
|
|
79
|
-
items.push(value);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
14
|
class ParameterConditionPlacementOptimizer {
|
|
83
15
|
plan(input, options = {}) {
|
|
84
16
|
var _a, _b, _c;
|
|
@@ -117,7 +49,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
117
49
|
const applied = [];
|
|
118
50
|
const skipped = [];
|
|
119
51
|
const movedTerms = [];
|
|
120
|
-
for (const term of query.whereClause ? collectTopLevelAndTerms(query.whereClause.condition) : []) {
|
|
52
|
+
for (const term of query.whereClause ? (0, PredicateExpressionUtils_1.collectTopLevelAndTerms)(query.whereClause.condition) : []) {
|
|
121
53
|
const candidate = this.analyzeCandidate(term, options);
|
|
122
54
|
if (!candidate) {
|
|
123
55
|
continue;
|
|
@@ -184,10 +116,10 @@ class ParameterConditionPlacementOptimizer {
|
|
|
184
116
|
toScopeId: target.scopeId,
|
|
185
117
|
reason: appliedReason,
|
|
186
118
|
parameterNames: candidate.parameterNames,
|
|
187
|
-
columnReferences: candidate.references.map(columnReferenceText)
|
|
119
|
+
columnReferences: candidate.references.map(PredicateExpressionUtils_1.columnReferenceText)
|
|
188
120
|
});
|
|
189
121
|
}
|
|
190
|
-
rebuildWhereWithoutTerms(query, new Set(movedTerms));
|
|
122
|
+
(0, PredicateExpressionUtils_1.rebuildWhereWithoutTerms)(query, new Set(movedTerms));
|
|
191
123
|
const sql = applied.length > 0 || (0, SqlComponentFormatter_1.hasSqlComponentFormatOverride)(options)
|
|
192
124
|
? (0, SqlComponentFormatter_1.formatSqlComponent)(query, options)
|
|
193
125
|
: parsed.sql;
|
|
@@ -285,7 +217,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
285
217
|
if (found) {
|
|
286
218
|
return;
|
|
287
219
|
}
|
|
288
|
-
const candidate = unwrapParens(value);
|
|
220
|
+
const candidate = (0, PredicateExpressionUtils_1.unwrapParens)(value);
|
|
289
221
|
if (candidate instanceof ValueComponent_1.BinaryExpression) {
|
|
290
222
|
visit(candidate.left);
|
|
291
223
|
visit(candidate.right);
|
|
@@ -346,7 +278,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
346
278
|
findUnsupportedParameterPredicateShape(expression) {
|
|
347
279
|
const visit = (value) => {
|
|
348
280
|
var _a;
|
|
349
|
-
const candidate = unwrapParens(value);
|
|
281
|
+
const candidate = (0, PredicateExpressionUtils_1.unwrapParens)(value);
|
|
350
282
|
if (candidate instanceof ValueComponent_1.BetweenExpression) {
|
|
351
283
|
return null;
|
|
352
284
|
}
|
|
@@ -383,8 +315,8 @@ class ParameterConditionPlacementOptimizer {
|
|
|
383
315
|
return visit(expression);
|
|
384
316
|
}
|
|
385
317
|
isSupportedInPredicate(expression) {
|
|
386
|
-
const left = unwrapParens(expression.left);
|
|
387
|
-
const right = unwrapParens(expression.right);
|
|
318
|
+
const left = (0, PredicateExpressionUtils_1.unwrapParens)(expression.left);
|
|
319
|
+
const right = (0, PredicateExpressionUtils_1.unwrapParens)(expression.right);
|
|
388
320
|
if (!(left instanceof ValueComponent_1.ColumnReference)) {
|
|
389
321
|
return false;
|
|
390
322
|
}
|
|
@@ -395,7 +327,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
395
327
|
return false;
|
|
396
328
|
}
|
|
397
329
|
return right.values.length > 0
|
|
398
|
-
&& right.values.every(value => unwrapParens(value) instanceof ValueComponent_1.ParameterExpression);
|
|
330
|
+
&& right.values.every(value => (0, PredicateExpressionUtils_1.unwrapParens)(value) instanceof ValueComponent_1.ParameterExpression);
|
|
399
331
|
}
|
|
400
332
|
resolveTarget(root, candidate) {
|
|
401
333
|
var _a;
|
|
@@ -529,7 +461,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
529
461
|
const namespace = column.getNamespace();
|
|
530
462
|
const columnName = column.column.name;
|
|
531
463
|
if (namespace) {
|
|
532
|
-
const matches = bindings.filter(binding => identifiersEqual(binding.alias, namespace));
|
|
464
|
+
const matches = bindings.filter(binding => (0, PredicateExpressionUtils_1.identifiersEqual)(binding.alias, namespace));
|
|
533
465
|
if (matches.length !== 1) {
|
|
534
466
|
return {
|
|
535
467
|
code: "AMBIGUOUS_COLUMN_SOURCE",
|
|
@@ -543,13 +475,13 @@ class ParameterConditionPlacementOptimizer {
|
|
|
543
475
|
if (matchCount === 0) {
|
|
544
476
|
return {
|
|
545
477
|
code: "COLUMN_NOT_AVAILABLE_UPSTREAM",
|
|
546
|
-
reason: `Column '${columnReferenceText(column)}' is not a direct output of the referenced source.`
|
|
478
|
+
reason: `Column '${(0, PredicateExpressionUtils_1.columnReferenceText)(column)}' is not a direct output of the referenced source.`
|
|
547
479
|
};
|
|
548
480
|
}
|
|
549
481
|
if (matchCount > 1) {
|
|
550
482
|
return {
|
|
551
483
|
code: "AMBIGUOUS_COLUMN_REFERENCE",
|
|
552
|
-
reason: `Column '${columnReferenceText(column)}' resolves to multiple outputs in the referenced source.`
|
|
484
|
+
reason: `Column '${(0, PredicateExpressionUtils_1.columnReferenceText)(column)}' resolves to multiple outputs in the referenced source.`
|
|
553
485
|
};
|
|
554
486
|
}
|
|
555
487
|
return matches[0];
|
|
@@ -743,7 +675,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
743
675
|
if (!(join.condition instanceof Clause_1.JoinOnClause)) {
|
|
744
676
|
return;
|
|
745
677
|
}
|
|
746
|
-
join.condition.condition = new ValueComponent_1.BinaryExpression(join.condition.condition, "and", cloneValueComponent(expression, options));
|
|
678
|
+
join.condition.condition = new ValueComponent_1.BinaryExpression(join.condition.condition, "and", (0, PredicateExpressionUtils_1.cloneValueComponent)(expression, options));
|
|
747
679
|
join.condition.condition = (0, TopLevelAndConditionDeduper_1.dedupeTopLevelAndConditions)(join.condition.condition, options);
|
|
748
680
|
}
|
|
749
681
|
resolveTargetColumnByOutputIndex(root, query, outputIndex, sourceColumn) {
|
|
@@ -754,7 +686,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
754
686
|
reason: `UNION branch does not expose column '${sourceColumn.column.name}' at output position ${outputIndex + 1}.`
|
|
755
687
|
};
|
|
756
688
|
}
|
|
757
|
-
else if (identifiersEqual(output.name, sourceColumn.column.name)) {
|
|
689
|
+
else if ((0, PredicateExpressionUtils_1.identifiersEqual)(output.name, sourceColumn.column.name)) {
|
|
758
690
|
const matches = this.collectDirectOutputMatches(root, query, sourceColumn.column.name);
|
|
759
691
|
if (matches.length > 1) {
|
|
760
692
|
return {
|
|
@@ -835,12 +767,12 @@ class ParameterConditionPlacementOptimizer {
|
|
|
835
767
|
const bindings = this.getSourceBindings(query.fromClause);
|
|
836
768
|
const namespace = column.getNamespace();
|
|
837
769
|
if (namespace) {
|
|
838
|
-
const matches = bindings.filter(binding => identifiersEqual(binding.alias, namespace));
|
|
770
|
+
const matches = bindings.filter(binding => (0, PredicateExpressionUtils_1.identifiersEqual)(binding.alias, namespace));
|
|
839
771
|
return matches.length === 1
|
|
840
772
|
? null
|
|
841
773
|
: {
|
|
842
774
|
code: "AMBIGUOUS_TARGET_COLUMN",
|
|
843
|
-
reason: `Target column '${columnReferenceText(column)}' is not uniquely resolvable in the destination query.`
|
|
775
|
+
reason: `Target column '${(0, PredicateExpressionUtils_1.columnReferenceText)(column)}' is not uniquely resolvable in the destination query.`
|
|
844
776
|
};
|
|
845
777
|
}
|
|
846
778
|
if (bindings.length === 1) {
|
|
@@ -857,16 +789,16 @@ class ParameterConditionPlacementOptimizer {
|
|
|
857
789
|
return false;
|
|
858
790
|
}
|
|
859
791
|
return groupBy.grouping.some(grouping => {
|
|
860
|
-
const candidate = unwrapParens(grouping);
|
|
792
|
+
const candidate = (0, PredicateExpressionUtils_1.unwrapParens)(grouping);
|
|
861
793
|
return candidate instanceof ValueComponent_1.ColumnReference
|
|
862
794
|
&& this.sameResolvableColumnInQuery(query, candidate, column);
|
|
863
795
|
});
|
|
864
796
|
}
|
|
865
797
|
sameResolvableColumnInQuery(query, left, right) {
|
|
866
|
-
if (sameColumnReference(left, right)) {
|
|
798
|
+
if ((0, PredicateExpressionUtils_1.sameColumnReference)(left, right)) {
|
|
867
799
|
return true;
|
|
868
800
|
}
|
|
869
|
-
if (!identifiersEqual(left.column.name, right.column.name)) {
|
|
801
|
+
if (!(0, PredicateExpressionUtils_1.identifiersEqual)(left.column.name, right.column.name)) {
|
|
870
802
|
return false;
|
|
871
803
|
}
|
|
872
804
|
const leftSource = this.resolveColumnSourceAlias(query, left);
|
|
@@ -880,17 +812,17 @@ class ParameterConditionPlacementOptimizer {
|
|
|
880
812
|
const bindings = this.getSourceBindings(query.fromClause);
|
|
881
813
|
const namespace = column.getNamespace();
|
|
882
814
|
if (namespace) {
|
|
883
|
-
const matches = bindings.filter(binding => identifiersEqual(binding.alias, namespace));
|
|
815
|
+
const matches = bindings.filter(binding => (0, PredicateExpressionUtils_1.identifiersEqual)(binding.alias, namespace));
|
|
884
816
|
return matches.length === 1 ? matches[0].alias : null;
|
|
885
817
|
}
|
|
886
818
|
return bindings.length === 1 ? bindings[0].alias : null;
|
|
887
819
|
}
|
|
888
820
|
rebaseCondition(expression, targetColumns, options) {
|
|
889
|
-
const cloned = cloneValueComponent(expression, options);
|
|
821
|
+
const cloned = (0, PredicateExpressionUtils_1.cloneValueComponent)(expression, options);
|
|
890
822
|
for (const reference of this.collectColumnReferences(cloned)) {
|
|
891
|
-
const target = targetColumns.find(item => sameColumnReference(reference, item.sourceColumn));
|
|
823
|
+
const target = targetColumns.find(item => (0, PredicateExpressionUtils_1.sameColumnReference)(reference, item.sourceColumn));
|
|
892
824
|
if (target) {
|
|
893
|
-
reference.qualifiedName = cloneColumnReference(target.targetColumn).qualifiedName;
|
|
825
|
+
reference.qualifiedName = (0, PredicateExpressionUtils_1.cloneColumnReference)(target.targetColumn).qualifiedName;
|
|
894
826
|
}
|
|
895
827
|
}
|
|
896
828
|
return cloned;
|
|
@@ -1027,7 +959,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1027
959
|
resolveUnionOutputIndex(root, firstBranch, outputColumnName) {
|
|
1028
960
|
const matches = [];
|
|
1029
961
|
this.collectSelectOutputs(root, firstBranch).forEach((item, index) => {
|
|
1030
|
-
if (identifiersEqual(item.name, outputColumnName)) {
|
|
962
|
+
if ((0, PredicateExpressionUtils_1.identifiersEqual)(item.name, outputColumnName)) {
|
|
1031
963
|
matches.push(index);
|
|
1032
964
|
}
|
|
1033
965
|
});
|
|
@@ -1051,7 +983,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1051
983
|
return collector.collect(query);
|
|
1052
984
|
}
|
|
1053
985
|
collectDirectOutputMatches(root, query, columnName, includeUnprovenPotential = false) {
|
|
1054
|
-
const collectedMatches = this.collectSelectOutputs(root, query).filter(item => identifiersEqual(item.name, columnName));
|
|
986
|
+
const collectedMatches = this.collectSelectOutputs(root, query).filter(item => (0, PredicateExpressionUtils_1.identifiersEqual)(item.name, columnName));
|
|
1055
987
|
if (collectedMatches.length > 0) {
|
|
1056
988
|
return this.hasExplicitOutputMatch(query, columnName)
|
|
1057
989
|
? [...collectedMatches, ...this.inferWildcardOutputMatches(root, query, columnName, true)]
|
|
@@ -1062,11 +994,11 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1062
994
|
hasExplicitOutputMatch(query, columnName) {
|
|
1063
995
|
return query.selectClause.items.some(item => {
|
|
1064
996
|
if (item.identifier) {
|
|
1065
|
-
return identifiersEqual(item.identifier.name, columnName);
|
|
997
|
+
return (0, PredicateExpressionUtils_1.identifiersEqual)(item.identifier.name, columnName);
|
|
1066
998
|
}
|
|
1067
999
|
return item.value instanceof ValueComponent_1.ColumnReference
|
|
1068
1000
|
&& item.value.column.name !== "*"
|
|
1069
|
-
&& identifiersEqual(item.value.column.name, columnName);
|
|
1001
|
+
&& (0, PredicateExpressionUtils_1.identifiersEqual)(item.value.column.name, columnName);
|
|
1070
1002
|
});
|
|
1071
1003
|
}
|
|
1072
1004
|
inferWildcardOutputMatches(root, query, columnName, includeUnprovenPotential) {
|
|
@@ -1099,7 +1031,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1099
1031
|
return this.resolveWildcardColumnFromBinding(root, query, bindings[0], columnName, includeUnprovenPotential);
|
|
1100
1032
|
}
|
|
1101
1033
|
const namespace = wildcard.getNamespace();
|
|
1102
|
-
const matches = bindings.filter(binding => identifiersEqual(binding.alias, namespace));
|
|
1034
|
+
const matches = bindings.filter(binding => (0, PredicateExpressionUtils_1.identifiersEqual)(binding.alias, namespace));
|
|
1103
1035
|
if (matches.length === 0) {
|
|
1104
1036
|
return null;
|
|
1105
1037
|
}
|
|
@@ -1127,7 +1059,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1127
1059
|
...((_d = (_c = root.withClause) === null || _c === void 0 ? void 0 : _c.tables) !== null && _d !== void 0 ? _d : [])
|
|
1128
1060
|
];
|
|
1129
1061
|
const collector = new SelectOutputCollector_1.SelectOutputCollector(null, commonTables.length > 0 ? commonTables : null);
|
|
1130
|
-
return collector.collect(source).filter(item => identifiersEqual(item.name, columnName));
|
|
1062
|
+
return collector.collect(source).filter(item => (0, PredicateExpressionUtils_1.identifiersEqual)(item.name, columnName));
|
|
1131
1063
|
}
|
|
1132
1064
|
createColumnForBinding(binding, columnName) {
|
|
1133
1065
|
return new ValueComponent_1.ColumnReference(binding.alias ? [binding.alias] : null, columnName);
|
|
@@ -1157,13 +1089,13 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1157
1089
|
}
|
|
1158
1090
|
findCte(root, name) {
|
|
1159
1091
|
var _a, _b;
|
|
1160
|
-
const normalized = normalizeIdentifier(name);
|
|
1092
|
+
const normalized = (0, PredicateExpressionUtils_1.normalizeIdentifier)(name);
|
|
1161
1093
|
const matches = ((_b = (_a = root.withClause) === null || _a === void 0 ? void 0 : _a.tables) !== null && _b !== void 0 ? _b : [])
|
|
1162
|
-
.filter(table => normalizeIdentifier(table.getSourceAliasName()) === normalized);
|
|
1094
|
+
.filter(table => (0, PredicateExpressionUtils_1.normalizeIdentifier)(table.getSourceAliasName()) === normalized);
|
|
1163
1095
|
return matches.length === 1 ? matches[0] : null;
|
|
1164
1096
|
}
|
|
1165
1097
|
countTableSourceReferences(query, tableName) {
|
|
1166
|
-
const normalized = normalizeIdentifier(tableName);
|
|
1098
|
+
const normalized = (0, PredicateExpressionUtils_1.normalizeIdentifier)(tableName);
|
|
1167
1099
|
let count = 0;
|
|
1168
1100
|
const visitSelect = (select) => {
|
|
1169
1101
|
var _a, _b;
|
|
@@ -1178,7 +1110,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1178
1110
|
if (select.fromClause) {
|
|
1179
1111
|
for (const binding of this.getSourceBindings(select.fromClause)) {
|
|
1180
1112
|
const source = binding.source.datasource;
|
|
1181
|
-
if (source instanceof Clause_1.TableSource && normalizeIdentifier(source.table.name) === normalized) {
|
|
1113
|
+
if (source instanceof Clause_1.TableSource && (0, PredicateExpressionUtils_1.normalizeIdentifier)(source.table.name) === normalized) {
|
|
1182
1114
|
count += 1;
|
|
1183
1115
|
}
|
|
1184
1116
|
if (source instanceof Clause_1.SubQuerySource) {
|
|
@@ -1204,7 +1136,7 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1204
1136
|
if (found) {
|
|
1205
1137
|
return;
|
|
1206
1138
|
}
|
|
1207
|
-
const candidate = unwrapParens(value);
|
|
1139
|
+
const candidate = (0, PredicateExpressionUtils_1.unwrapParens)(value);
|
|
1208
1140
|
if (candidate instanceof ValueComponent_1.FunctionCall) {
|
|
1209
1141
|
if (candidate.over) {
|
|
1210
1142
|
found = true;
|
|
@@ -1254,9 +1186,9 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1254
1186
|
collectColumnReferences(expression) {
|
|
1255
1187
|
const references = [];
|
|
1256
1188
|
const visit = (value) => {
|
|
1257
|
-
const candidate = unwrapParens(value);
|
|
1189
|
+
const candidate = (0, PredicateExpressionUtils_1.unwrapParens)(value);
|
|
1258
1190
|
if (candidate instanceof ValueComponent_1.ColumnReference) {
|
|
1259
|
-
if (!references.some(existing => sameColumnReference(existing, candidate))) {
|
|
1191
|
+
if (!references.some(existing => (0, PredicateExpressionUtils_1.sameColumnReference)(existing, candidate))) {
|
|
1260
1192
|
references.push(candidate);
|
|
1261
1193
|
}
|
|
1262
1194
|
return;
|
|
@@ -1328,9 +1260,9 @@ class ParameterConditionPlacementOptimizer {
|
|
|
1328
1260
|
collectParameterNames(expression) {
|
|
1329
1261
|
const names = [];
|
|
1330
1262
|
const visit = (value) => {
|
|
1331
|
-
const candidate = unwrapParens(value);
|
|
1263
|
+
const candidate = (0, PredicateExpressionUtils_1.unwrapParens)(value);
|
|
1332
1264
|
if (candidate instanceof ValueComponent_1.ParameterExpression) {
|
|
1333
|
-
appendUnique(names, candidate.name.value);
|
|
1265
|
+
(0, PredicateExpressionUtils_1.appendUnique)(names, candidate.name.value);
|
|
1334
1266
|
return;
|
|
1335
1267
|
}
|
|
1336
1268
|
if (candidate instanceof ValueComponent_1.BinaryExpression) {
|