rawsql-ts 0.25.0 → 0.26.1
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 +3 -0
- package/dist/esm/index.js +3 -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/ConditionOptimization.d.ts +75 -0
- package/dist/esm/transformers/ConditionOptimization.js +310 -0
- package/dist/esm/transformers/ConditionOptimization.js.map +1 -0
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.d.ts +85 -0
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js +939 -0
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js.map +1 -0
- package/dist/esm/transformers/SSSQLFilterBuilder.d.ts +6 -0
- package/dist/esm/transformers/SSSQLFilterBuilder.js +84 -8
- package/dist/esm/transformers/SSSQLFilterBuilder.js.map +1 -1
- package/dist/esm/transformers/SqlComponentFormatter.d.ts +3 -0
- package/dist/esm/transformers/SqlComponentFormatter.js +7 -0
- package/dist/esm/transformers/SqlComponentFormatter.js.map +1 -0
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.d.ts +85 -0
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js +1198 -0
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js.map +1 -0
- package/dist/index.js +3 -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 +3 -0
- package/dist/src/transformers/ConditionOptimization.d.ts +75 -0
- package/dist/src/transformers/ParameterConditionPlacementOptimizer.d.ts +85 -0
- package/dist/src/transformers/SSSQLFilterBuilder.d.ts +6 -0
- package/dist/src/transformers/SqlComponentFormatter.d.ts +3 -0
- package/dist/src/transformers/StaticPredicatePlacementOptimizer.d.ts +85 -0
- package/dist/transformers/ConditionOptimization.js +339 -0
- package/dist/transformers/ConditionOptimization.js.map +1 -0
- package/dist/transformers/ParameterConditionPlacementOptimizer.js +949 -0
- package/dist/transformers/ParameterConditionPlacementOptimizer.js.map +1 -0
- package/dist/transformers/SSSQLFilterBuilder.js +92 -16
- package/dist/transformers/SSSQLFilterBuilder.js.map +1 -1
- package/dist/transformers/SqlComponentFormatter.js +11 -0
- package/dist/transformers/SqlComponentFormatter.js.map +1 -0
- package/dist/transformers/StaticPredicatePlacementOptimizer.js +1208 -0
- package/dist/transformers/StaticPredicatePlacementOptimizer.js.map +1 -0
- package/dist/tsconfig.browser.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
|
2
|
+
import { ParameterConditionMove, ParameterConditionOptimizationError, ParameterConditionOptimizationOptions, ParameterConditionOptimizationWarning, ParameterConditionSkipped } from "./ParameterConditionPlacementOptimizer";
|
|
3
|
+
import { StaticPredicateMove, StaticPredicatePlacementError, StaticPredicatePlacementWarning, StaticPredicateSkipped } from "./StaticPredicatePlacementOptimizer";
|
|
4
|
+
import { OptionalConditionPruningParameters } from "./PruneOptionalConditionBranches";
|
|
5
|
+
export type ConditionOptimizationInput = string | SelectQuery | SimpleSelectQuery;
|
|
6
|
+
export type ConditionOptimizationPhaseKind = "sssql_optional_condition" | "parameter_condition_placement" | "static_predicate_placement";
|
|
7
|
+
export interface ConditionOptimizationOptions extends ParameterConditionOptimizationOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Explicit opt-in values for SSSQL optional branch pruning.
|
|
10
|
+
* Only listed parameter names are considered, and only null/undefined values
|
|
11
|
+
* are pruned by the safe-only SSSQL phase.
|
|
12
|
+
*/
|
|
13
|
+
optionalConditionParameters?: OptionalConditionPruningParameters;
|
|
14
|
+
}
|
|
15
|
+
export interface ConditionOptimizationPhaseSummary {
|
|
16
|
+
kind: ConditionOptimizationPhaseKind;
|
|
17
|
+
appliedCount: number;
|
|
18
|
+
skippedCount: number;
|
|
19
|
+
warningCount: number;
|
|
20
|
+
errorCount: number;
|
|
21
|
+
}
|
|
22
|
+
export interface SssqlOptionalConditionApplied {
|
|
23
|
+
phaseKind: "sssql_optional_condition";
|
|
24
|
+
kind: "prune_optional_branch" | "refresh_optional_branch";
|
|
25
|
+
conditionSql: string;
|
|
26
|
+
parameterName: string;
|
|
27
|
+
reason: string;
|
|
28
|
+
previousConditionSql?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SssqlOptionalConditionSkipped {
|
|
31
|
+
phaseKind: "sssql_optional_condition";
|
|
32
|
+
kind: "optional_branch_skipped";
|
|
33
|
+
conditionSql: string;
|
|
34
|
+
parameterName: string;
|
|
35
|
+
code: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
}
|
|
38
|
+
export type ConditionOptimizationApplied = SssqlOptionalConditionApplied | (ParameterConditionMove & {
|
|
39
|
+
phaseKind: "parameter_condition_placement";
|
|
40
|
+
}) | (StaticPredicateMove & {
|
|
41
|
+
phaseKind: "static_predicate_placement";
|
|
42
|
+
});
|
|
43
|
+
export type ConditionOptimizationSkipped = SssqlOptionalConditionSkipped | (ParameterConditionSkipped & {
|
|
44
|
+
phaseKind: "parameter_condition_placement";
|
|
45
|
+
}) | (StaticPredicateSkipped & {
|
|
46
|
+
phaseKind: "static_predicate_placement";
|
|
47
|
+
});
|
|
48
|
+
export type ConditionOptimizationWarning = (ParameterConditionOptimizationWarning & {
|
|
49
|
+
phaseKind: ConditionOptimizationPhaseKind;
|
|
50
|
+
}) | (StaticPredicatePlacementWarning & {
|
|
51
|
+
phaseKind: ConditionOptimizationPhaseKind;
|
|
52
|
+
});
|
|
53
|
+
export type ConditionOptimizationError = (ParameterConditionOptimizationError & {
|
|
54
|
+
phaseKind: ConditionOptimizationPhaseKind;
|
|
55
|
+
}) | (StaticPredicatePlacementError & {
|
|
56
|
+
phaseKind: ConditionOptimizationPhaseKind;
|
|
57
|
+
});
|
|
58
|
+
export interface ConditionOptimizationSafety {
|
|
59
|
+
mode: "safe_only";
|
|
60
|
+
unsafeRewriteApplied: false;
|
|
61
|
+
dryRun: boolean;
|
|
62
|
+
formatterGeneratedSource: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ConditionOptimizationResult {
|
|
65
|
+
ok: boolean;
|
|
66
|
+
sql: string;
|
|
67
|
+
phases: readonly ConditionOptimizationPhaseSummary[];
|
|
68
|
+
applied: readonly ConditionOptimizationApplied[];
|
|
69
|
+
skipped: readonly ConditionOptimizationSkipped[];
|
|
70
|
+
warnings: readonly ConditionOptimizationWarning[];
|
|
71
|
+
errors: readonly ConditionOptimizationError[];
|
|
72
|
+
safety: ConditionOptimizationSafety;
|
|
73
|
+
}
|
|
74
|
+
export declare const planConditionOptimization: (input: ConditionOptimizationInput, options?: ConditionOptimizationOptions) => ConditionOptimizationResult;
|
|
75
|
+
export declare const optimizeConditions: (input: ConditionOptimizationInput, options?: ConditionOptimizationOptions) => ConditionOptimizationResult;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { SelectQueryParser } from "../parsers/SelectQueryParser";
|
|
2
|
+
import { optimizeParameterConditionPlacement, planParameterConditionOptimization } from "./ParameterConditionPlacementOptimizer";
|
|
3
|
+
import { optimizeStaticPredicatePlacement, planStaticPredicatePlacement } from "./StaticPredicatePlacementOptimizer";
|
|
4
|
+
import { collectSupportedOptionalConditionBranches, pruneOptionalConditionBranches } from "./PruneOptionalConditionBranches";
|
|
5
|
+
import { SSSQLFilterBuilder } from "./SSSQLFilterBuilder";
|
|
6
|
+
import { formatSqlComponent } from "./SqlComponentFormatter";
|
|
7
|
+
const hasOwnParameter = (parameters, parameterName) => Object.prototype.hasOwnProperty.call(parameters, parameterName);
|
|
8
|
+
const isAbsentOptionalValue = (parameters, parameterName) => parameters[parameterName] === null || parameters[parameterName] === undefined;
|
|
9
|
+
const parseConditionOptimizationInput = (input) => {
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const errors = [];
|
|
12
|
+
const sourceSql = typeof input === "string" ? input : formatSqlComponent(input);
|
|
13
|
+
const formatterGeneratedSource = typeof input !== "string";
|
|
14
|
+
if (formatterGeneratedSource) {
|
|
15
|
+
warnings.push({
|
|
16
|
+
phaseKind: "sssql_optional_condition",
|
|
17
|
+
code: "AST_INPUT_FORMATTED",
|
|
18
|
+
message: "AST input is cloned through formatter output so the caller-owned query is not mutated."
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return {
|
|
23
|
+
query: SelectQueryParser.parse(sourceSql),
|
|
24
|
+
sql: sourceSql,
|
|
25
|
+
formatterGeneratedSource,
|
|
26
|
+
warnings,
|
|
27
|
+
errors
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
errors.push({
|
|
32
|
+
phaseKind: "sssql_optional_condition",
|
|
33
|
+
code: "PARSE_FAILED",
|
|
34
|
+
message: "SSSQL optional condition optimization could not parse the input SQL.",
|
|
35
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
query: null,
|
|
39
|
+
sql: sourceSql,
|
|
40
|
+
formatterGeneratedSource,
|
|
41
|
+
warnings,
|
|
42
|
+
errors
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const buildSssqlApplied = (branch) => {
|
|
47
|
+
return {
|
|
48
|
+
phaseKind: "sssql_optional_condition",
|
|
49
|
+
kind: "prune_optional_branch",
|
|
50
|
+
conditionSql: formatSqlComponent(branch.expression),
|
|
51
|
+
parameterName: branch.parameterName,
|
|
52
|
+
reason: "The optional branch parameter is explicitly absent, so the safe-only SSSQL phase pruned the branch."
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const buildSssqlRefreshApplied = (branch, previousConditionSql) => {
|
|
56
|
+
return {
|
|
57
|
+
phaseKind: "sssql_optional_condition",
|
|
58
|
+
kind: "refresh_optional_branch",
|
|
59
|
+
conditionSql: formatSqlComponent(branch.expression),
|
|
60
|
+
previousConditionSql,
|
|
61
|
+
parameterName: branch.parameterName,
|
|
62
|
+
reason: "The safe-only SSSQL phase refreshed the optional branch placement before ordinary parameter placement."
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const buildSssqlSkipped = (branch, parameters) => {
|
|
66
|
+
const parameterProvided = hasOwnParameter(parameters, branch.parameterName);
|
|
67
|
+
return {
|
|
68
|
+
phaseKind: "sssql_optional_condition",
|
|
69
|
+
kind: "optional_branch_skipped",
|
|
70
|
+
conditionSql: formatSqlComponent(branch.expression),
|
|
71
|
+
parameterName: branch.parameterName,
|
|
72
|
+
code: parameterProvided
|
|
73
|
+
? "SSSQL_OPTIONAL_PARAMETER_PRESENT"
|
|
74
|
+
: "SSSQL_OPTIONAL_PARAMETER_NOT_PROVIDED",
|
|
75
|
+
reason: parameterProvided
|
|
76
|
+
? "The optional branch parameter is present, so the branch remains active."
|
|
77
|
+
: "No optional branch parameter value was provided, so the branch remains unchanged."
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const buildSssqlRefreshSkipped = (branch, code, reason) => {
|
|
81
|
+
return {
|
|
82
|
+
phaseKind: "sssql_optional_condition",
|
|
83
|
+
kind: "optional_branch_skipped",
|
|
84
|
+
conditionSql: formatSqlComponent(branch.expression),
|
|
85
|
+
parameterName: branch.parameterName,
|
|
86
|
+
code,
|
|
87
|
+
reason
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const buildSssqlRefreshFilters = (branches, parameters) => {
|
|
91
|
+
const filters = {};
|
|
92
|
+
for (const branch of branches) {
|
|
93
|
+
filters[branch.parameterName] = hasOwnParameter(parameters, branch.parameterName)
|
|
94
|
+
? parameters[branch.parameterName]
|
|
95
|
+
: null;
|
|
96
|
+
}
|
|
97
|
+
return filters;
|
|
98
|
+
};
|
|
99
|
+
const refreshRemainingSssqlBranches = (sql, parameters) => {
|
|
100
|
+
const parsed = parseConditionOptimizationInput(sql);
|
|
101
|
+
const applied = [];
|
|
102
|
+
const skipped = [];
|
|
103
|
+
if (!parsed.query) {
|
|
104
|
+
return {
|
|
105
|
+
sql: parsed.sql,
|
|
106
|
+
applied,
|
|
107
|
+
skipped,
|
|
108
|
+
warnings: parsed.warnings,
|
|
109
|
+
errors: parsed.errors,
|
|
110
|
+
formatterGeneratedSource: parsed.formatterGeneratedSource
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const beforeBranches = collectSupportedOptionalConditionBranches(parsed.query);
|
|
114
|
+
if (beforeBranches.length === 0) {
|
|
115
|
+
return {
|
|
116
|
+
sql: parsed.sql,
|
|
117
|
+
applied,
|
|
118
|
+
skipped,
|
|
119
|
+
warnings: parsed.warnings,
|
|
120
|
+
errors: parsed.errors,
|
|
121
|
+
formatterGeneratedSource: parsed.formatterGeneratedSource
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const beforeBranchSql = new WeakMap();
|
|
125
|
+
const beforeBranchQuery = new WeakMap();
|
|
126
|
+
for (const branch of beforeBranches) {
|
|
127
|
+
beforeBranchSql.set(branch.expression, formatSqlComponent(branch.expression));
|
|
128
|
+
beforeBranchQuery.set(branch.expression, branch.query);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
new SSSQLFilterBuilder().refresh(parsed.query, buildSssqlRefreshFilters(beforeBranches, parameters));
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
135
|
+
return {
|
|
136
|
+
sql,
|
|
137
|
+
applied,
|
|
138
|
+
skipped: beforeBranches.map(branch => buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", `SSSQL optional branch refresh was skipped because safe refresh could not be proven: ${detail}`)),
|
|
139
|
+
warnings: parsed.warnings,
|
|
140
|
+
errors: parsed.errors,
|
|
141
|
+
formatterGeneratedSource: parsed.formatterGeneratedSource
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const afterBranches = collectSupportedOptionalConditionBranches(parsed.query);
|
|
145
|
+
for (const branch of afterBranches) {
|
|
146
|
+
const previousSql = beforeBranchSql.get(branch.expression);
|
|
147
|
+
const previousQuery = beforeBranchQuery.get(branch.expression);
|
|
148
|
+
if (!previousSql || !previousQuery) {
|
|
149
|
+
skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", "SSSQL optional branch refresh left an untracked branch unchanged."));
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const refreshedSql = formatSqlComponent(branch.expression);
|
|
153
|
+
if (previousQuery !== branch.query || previousSql !== refreshedSql) {
|
|
154
|
+
applied.push(buildSssqlRefreshApplied(branch, previousSql));
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_NOOP", "SSSQL optional branch refresh found no safe placement change to apply."));
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
sql: applied.length > 0 ? formatSqlComponent(parsed.query) : sql,
|
|
161
|
+
applied,
|
|
162
|
+
skipped,
|
|
163
|
+
warnings: parsed.warnings,
|
|
164
|
+
errors: parsed.errors,
|
|
165
|
+
formatterGeneratedSource: parsed.formatterGeneratedSource
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const runSssqlOptionalConditionPhase = (input, options) => {
|
|
169
|
+
var _a;
|
|
170
|
+
const parsed = parseConditionOptimizationInput(input);
|
|
171
|
+
const warnings = [...parsed.warnings];
|
|
172
|
+
let errors = [...parsed.errors];
|
|
173
|
+
const applied = [];
|
|
174
|
+
const skipped = [];
|
|
175
|
+
const optionalConditionParameters = (_a = options.optionalConditionParameters) !== null && _a !== void 0 ? _a : {};
|
|
176
|
+
if (!parsed.query) {
|
|
177
|
+
return {
|
|
178
|
+
sql: parsed.sql,
|
|
179
|
+
applied,
|
|
180
|
+
skipped,
|
|
181
|
+
warnings,
|
|
182
|
+
errors,
|
|
183
|
+
formatterGeneratedSource: parsed.formatterGeneratedSource
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
let currentSql = parsed.sql;
|
|
187
|
+
const branches = collectSupportedOptionalConditionBranches(parsed.query);
|
|
188
|
+
const pruneBranches = branches.filter(branch => hasOwnParameter(optionalConditionParameters, branch.parameterName)
|
|
189
|
+
&& isAbsentOptionalValue(optionalConditionParameters, branch.parameterName));
|
|
190
|
+
if (pruneBranches.length > 0) {
|
|
191
|
+
try {
|
|
192
|
+
pruneOptionalConditionBranches(parsed.query, optionalConditionParameters);
|
|
193
|
+
currentSql = formatSqlComponent(parsed.query);
|
|
194
|
+
applied.push(...pruneBranches.map(buildSssqlApplied));
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
errors = [...errors, {
|
|
198
|
+
phaseKind: "sssql_optional_condition",
|
|
199
|
+
code: "SSSQL_PRUNE_FAILED",
|
|
200
|
+
message: "SSSQL optional condition optimization could not prune optional branches.",
|
|
201
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
202
|
+
}];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (errors.length === 0) {
|
|
206
|
+
const refreshPhase = refreshRemainingSssqlBranches(currentSql, optionalConditionParameters);
|
|
207
|
+
applied.push(...refreshPhase.applied);
|
|
208
|
+
skipped.push(...refreshPhase.skipped);
|
|
209
|
+
warnings.push(...refreshPhase.warnings);
|
|
210
|
+
errors.push(...refreshPhase.errors);
|
|
211
|
+
currentSql = refreshPhase.sql;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
for (const branch of branches) {
|
|
215
|
+
if (pruneBranches.includes(branch)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
skipped.push(buildSssqlSkipped(branch, optionalConditionParameters));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
sql: errors.length === 0 ? currentSql : parsed.sql,
|
|
223
|
+
applied,
|
|
224
|
+
skipped,
|
|
225
|
+
warnings,
|
|
226
|
+
errors,
|
|
227
|
+
formatterGeneratedSource: parsed.formatterGeneratedSource
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
const mapParameterWarnings = (warnings) => warnings.map(warning => (Object.assign({ phaseKind: "parameter_condition_placement" }, warning)));
|
|
231
|
+
const mapParameterErrors = (errors) => errors.map(error => (Object.assign({ phaseKind: "parameter_condition_placement" }, error)));
|
|
232
|
+
const mapParameterApplied = (applied) => applied.map(item => (Object.assign({ phaseKind: "parameter_condition_placement" }, item)));
|
|
233
|
+
const mapParameterSkipped = (skipped) => skipped.map(item => (Object.assign({ phaseKind: "parameter_condition_placement" }, item)));
|
|
234
|
+
const mapStaticWarnings = (warnings) => warnings.map(warning => (Object.assign({ phaseKind: "static_predicate_placement" }, warning)));
|
|
235
|
+
const mapStaticErrors = (errors) => errors.map(error => (Object.assign({ phaseKind: "static_predicate_placement" }, error)));
|
|
236
|
+
const mapStaticApplied = (applied) => applied.map(item => (Object.assign({ phaseKind: "static_predicate_placement" }, item)));
|
|
237
|
+
const mapStaticSkipped = (skipped) => skipped.map(item => (Object.assign({ phaseKind: "static_predicate_placement" }, item)));
|
|
238
|
+
const makePhaseSummary = (kind, counts) => ({
|
|
239
|
+
kind,
|
|
240
|
+
appliedCount: counts.appliedCount,
|
|
241
|
+
skippedCount: counts.skippedCount,
|
|
242
|
+
warningCount: counts.warningCount,
|
|
243
|
+
errorCount: counts.errorCount
|
|
244
|
+
});
|
|
245
|
+
const runConditionOptimization = (input, options, defaultDryRun) => {
|
|
246
|
+
var _a;
|
|
247
|
+
const dryRun = (_a = options.dryRun) !== null && _a !== void 0 ? _a : defaultDryRun;
|
|
248
|
+
// Run semantic SSSQL handling before generic placement phases so optional
|
|
249
|
+
// branches remain owned by SSSQL even if later phases grow broader support.
|
|
250
|
+
const sssqlPhase = runSssqlOptionalConditionPhase(input, Object.assign(Object.assign({}, options), { dryRun }));
|
|
251
|
+
const parameterPhase = dryRun
|
|
252
|
+
? planParameterConditionOptimization(sssqlPhase.sql, { dryRun })
|
|
253
|
+
: optimizeParameterConditionPlacement(sssqlPhase.sql, { dryRun });
|
|
254
|
+
const parameterWarnings = mapParameterWarnings(parameterPhase.warnings);
|
|
255
|
+
const parameterErrors = mapParameterErrors(parameterPhase.errors);
|
|
256
|
+
const parameterApplied = mapParameterApplied(parameterPhase.applied);
|
|
257
|
+
const parameterSkipped = mapParameterSkipped(parameterPhase.skipped);
|
|
258
|
+
const staticPhase = dryRun
|
|
259
|
+
? planStaticPredicatePlacement(parameterPhase.sql, { dryRun })
|
|
260
|
+
: optimizeStaticPredicatePlacement(parameterPhase.sql, { dryRun });
|
|
261
|
+
const staticWarnings = mapStaticWarnings(staticPhase.warnings);
|
|
262
|
+
const staticErrors = mapStaticErrors(staticPhase.errors);
|
|
263
|
+
const staticApplied = mapStaticApplied(staticPhase.applied);
|
|
264
|
+
const staticSkipped = mapStaticSkipped(staticPhase.skipped);
|
|
265
|
+
const warnings = [...sssqlPhase.warnings, ...parameterWarnings, ...staticWarnings];
|
|
266
|
+
const errors = [...sssqlPhase.errors, ...parameterErrors, ...staticErrors];
|
|
267
|
+
return {
|
|
268
|
+
ok: errors.length === 0,
|
|
269
|
+
sql: staticPhase.sql,
|
|
270
|
+
phases: [
|
|
271
|
+
makePhaseSummary("sssql_optional_condition", {
|
|
272
|
+
appliedCount: sssqlPhase.applied.length,
|
|
273
|
+
skippedCount: sssqlPhase.skipped.length,
|
|
274
|
+
warningCount: sssqlPhase.warnings.length,
|
|
275
|
+
errorCount: sssqlPhase.errors.length
|
|
276
|
+
}),
|
|
277
|
+
makePhaseSummary("parameter_condition_placement", {
|
|
278
|
+
appliedCount: parameterApplied.length,
|
|
279
|
+
skippedCount: parameterSkipped.length,
|
|
280
|
+
warningCount: parameterWarnings.length,
|
|
281
|
+
errorCount: parameterErrors.length
|
|
282
|
+
}),
|
|
283
|
+
makePhaseSummary("static_predicate_placement", {
|
|
284
|
+
appliedCount: staticApplied.length,
|
|
285
|
+
skippedCount: staticSkipped.length,
|
|
286
|
+
warningCount: staticWarnings.length,
|
|
287
|
+
errorCount: staticErrors.length
|
|
288
|
+
})
|
|
289
|
+
],
|
|
290
|
+
applied: [...sssqlPhase.applied, ...parameterApplied, ...staticApplied],
|
|
291
|
+
skipped: [...sssqlPhase.skipped, ...parameterSkipped, ...staticSkipped],
|
|
292
|
+
warnings,
|
|
293
|
+
errors,
|
|
294
|
+
safety: {
|
|
295
|
+
mode: "safe_only",
|
|
296
|
+
unsafeRewriteApplied: false,
|
|
297
|
+
dryRun,
|
|
298
|
+
formatterGeneratedSource: sssqlPhase.formatterGeneratedSource
|
|
299
|
+
|| parameterPhase.safety.formatterGeneratedSource
|
|
300
|
+
|| staticPhase.safety.formatterGeneratedSource
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
export const planConditionOptimization = (input, options = {}) => {
|
|
305
|
+
return runConditionOptimization(input, options, true);
|
|
306
|
+
};
|
|
307
|
+
export const optimizeConditions = (input, options = {}) => {
|
|
308
|
+
return runConditionOptimization(input, options, false);
|
|
309
|
+
};
|
|
310
|
+
//# sourceMappingURL=ConditionOptimization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionOptimization.js","sourceRoot":"","sources":["../../../src/transformers/ConditionOptimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACH,mCAAmC,EAMnC,kCAAkC,EACrC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACH,gCAAgC,EAChC,4BAA4B,EAK/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,yCAAyC,EAEzC,8BAA8B,EAEjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAgG7D,MAAM,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gB,EAAE,GAAG,aAAa,CAAC;QACvE,QAAQ;QACR,MAAM;QACN,MAAM,EAAE;YACJ,IAAI,EAAE,WAAW;YACjB,oBAAoB,EAAE,KAAK;YAC3B,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;mBACtD,cAAc,CAAC,MAAM,CAAC,wBAAwB;mBAC9C,WAAW,CAAC,MAAM,CAAC,wBAAwB;SACrD;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACrC,KAAiC,EACjC,UAAwC,EAAE,EACf,EAAE;IAC7B,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,KAAiC,EACjC,UAAwC,EAAE,EACf,EAAE;IAC7B,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
|
2
|
+
export type ParameterConditionOptimizationInput = string | SelectQuery | SimpleSelectQuery;
|
|
3
|
+
/**
|
|
4
|
+
* First-phase safe-only placement for ordinary parameter predicates.
|
|
5
|
+
*
|
|
6
|
+
* The optimizer intentionally handles only root top-level AND predicates and one
|
|
7
|
+
* CTE/derived-table hop where the destination output is a direct column reference.
|
|
8
|
+
* Unsupported boundaries such as OR, UNION, DISTINCT, GROUP BY, WINDOW, OUTER
|
|
9
|
+
* JOIN, expression outputs, and function predicates are reported as skipped.
|
|
10
|
+
*/
|
|
11
|
+
export interface ParameterConditionOptimizationOptions {
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ParameterConditionOptimizationWarning {
|
|
15
|
+
code: string;
|
|
16
|
+
message: string;
|
|
17
|
+
detail?: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface ParameterConditionOptimizationError {
|
|
20
|
+
code: string;
|
|
21
|
+
message: string;
|
|
22
|
+
detail?: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface ParameterConditionMove {
|
|
25
|
+
kind: "move_condition";
|
|
26
|
+
conditionSql: string;
|
|
27
|
+
fromScopeId: string;
|
|
28
|
+
toScopeId: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
parameterNames: readonly string[];
|
|
31
|
+
columnReferences: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
export interface ParameterConditionSkipped {
|
|
34
|
+
conditionSql: string;
|
|
35
|
+
scopeId: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
code: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ParameterConditionOptimizationSafety {
|
|
40
|
+
mode: "safe_only";
|
|
41
|
+
unsafeRewriteApplied: false;
|
|
42
|
+
dryRun: boolean;
|
|
43
|
+
formatterGeneratedSource: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface ParameterConditionOptimizationResult {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
sql: string;
|
|
48
|
+
applied: readonly ParameterConditionMove[];
|
|
49
|
+
skipped: readonly ParameterConditionSkipped[];
|
|
50
|
+
warnings: readonly ParameterConditionOptimizationWarning[];
|
|
51
|
+
errors: readonly ParameterConditionOptimizationError[];
|
|
52
|
+
safety: ParameterConditionOptimizationSafety;
|
|
53
|
+
conditionMoves: readonly ParameterConditionMove[];
|
|
54
|
+
}
|
|
55
|
+
export declare class ParameterConditionPlacementOptimizer {
|
|
56
|
+
plan(input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions): ParameterConditionOptimizationResult;
|
|
57
|
+
optimize(input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions): ParameterConditionOptimizationResult;
|
|
58
|
+
private parseInput;
|
|
59
|
+
private analyzeCandidate;
|
|
60
|
+
private findUnsupportedExpression;
|
|
61
|
+
private isSupportedInPredicate;
|
|
62
|
+
private resolveTarget;
|
|
63
|
+
private findCurrentQueryBoundary;
|
|
64
|
+
private findTargetQueryBoundary;
|
|
65
|
+
private resolveSourceBinding;
|
|
66
|
+
private resolveUpstreamQuery;
|
|
67
|
+
private resolveTargetColumn;
|
|
68
|
+
private verifyColumnResolvableInQuery;
|
|
69
|
+
private rebaseCondition;
|
|
70
|
+
private getSourceBindings;
|
|
71
|
+
private findNullableSideBoundary;
|
|
72
|
+
private hasOuterJoin;
|
|
73
|
+
private getOutputColumnMatchCount;
|
|
74
|
+
private resolveSourceQueryForColumns;
|
|
75
|
+
private getSelectItemOutputName;
|
|
76
|
+
private findCte;
|
|
77
|
+
private countTableSourceReferences;
|
|
78
|
+
private hasWindowUsage;
|
|
79
|
+
private collectColumnReferences;
|
|
80
|
+
private collectParameterNames;
|
|
81
|
+
private makeSkipped;
|
|
82
|
+
private buildResult;
|
|
83
|
+
}
|
|
84
|
+
export declare const planParameterConditionOptimization: (input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions) => ParameterConditionOptimizationResult;
|
|
85
|
+
export declare const optimizeParameterConditionPlacement: (input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions) => ParameterConditionOptimizationResult;
|