MCPcopy Create free account
hub / github.com/BaseXdb/basex / optimize

Method optimize

basex-core/src/main/java/org/basex/query/expr/path/Path.java:153–193  ·  view source on GitHub ↗
(final CompileContext cc)

Source from the content-addressed store, hash-verified

151 }
152
153 @Override
154 public final Expr optimize(final CompileContext cc) throws QueryException {
155 // no root, no nesting: assign context value (can be null)
156 if(root == null && !cc.nestedFocus()) root = cc.qc.focus.value;
157
158 // remove redundant steps, find empty steps
159 Expr expr = simplify(cc);
160 if(expr != this) return expr;
161
162 // flatten nested path expressions
163 expr = flatten(cc);
164 // rewrite list to union expressions
165 if(expr == this) expr = toUnion(cc);
166 // merge adjacent steps
167 if(expr == this) expr = mergeSteps(cc);
168 // move predicates downward
169 if(expr == this) expr = movePredicates(cc);
170 // return optimized expression
171 if(expr != this) return expr.optimize(cc);
172
173 // assign sequence type, compute result size
174 final Expr rt = root != null ? root : cc.qc.focus.value;
175 seqType(rt);
176
177 // remove paths that will yield no result
178 expr = removeEmpty(cc, rt);
179 // rewrite to simple map
180 if(expr == this) expr = toMap(cc);
181 // check index access
182 if(expr == this) expr = index(cc, rt);
183 /* rewrite descendant to child steps. this optimization is called after the index rewritings,
184 * as it is cheaper to invert a descendant step. examples:
185 * - //B [. = '...'] → IA('...', B)
186 * - /A/B[. = '...'] → IA('...', B)/parent::A *[parent::document-node()] */
187 if(expr == this) expr = children(cc, rt);
188 // return optimized expression
189 if(expr != this) return expr;
190
191 // choose the best path implementation (dummy will be used for type checking)
192 return copyType(get(info, root == null && rt instanceof Dummy ? rt : root, steps));
193 }
194
195 @Override
196 public final Expr simplifyFor(final Simplify mode, final CompileContext cc)

Callers 4

compileMethod · 0.95
inlineMethod · 0.95
getMethod · 0.45
mergeEbvMethod · 0.45

Calls 14

simplifyMethod · 0.95
flattenMethod · 0.95
toUnionMethod · 0.95
mergeStepsMethod · 0.95
movePredicatesMethod · 0.95
optimizeMethod · 0.95
seqTypeMethod · 0.95
removeEmptyMethod · 0.95
toMapMethod · 0.95
indexMethod · 0.95
childrenMethod · 0.95
getMethod · 0.95

Tested by

no test coverage detected