You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2026/09/08 18:30:59 UTC

[XL] Change in asterixdb[master]: [ASTERIXDB-3823][COMP] Sample the join key expression, not a column

From Ritik Raj <ri...@couchbase.com>:

Attention is currently required from: Ritik Raj.

Hello Ali Alsuliman, Anon. E. Moose #1000171, Jenkins, 

I'd like you to reexamine a change. Please visit

    https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21551?usp=email

to look at the new patch set (#7).

The following approvals got outdated and were removed:
Contrib+1 by Anon. E. Moose #1000171, Integration-Tests+1 by Jenkins


Change subject: [ASTERIXDB-3823][COMP] Sample the join key expression, not a column
......................................................................

[ASTERIXDB-3823][COMP] Sample the join key expression, not a column

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- naiveJoinSelectivity paired the join predicate's used variables
  positionally with the two leaf inputs, taking exprUsedVars.get(0) for
  idx1 and get(1) for idx2. When one side of the predicate is a computed
  expression, the defining ASSIGN is inlined into the condition, so the
  predicate carries more than two variables in no particular order and
  the positional pick can return a variable the chosen leaf input does
  not produce. runSamplingQueryDistinct then aggregated an untyped
  variable and typing the sampling plan threw a NullPointerException,
  failing compilation of a valid query.
- Derive the join key from the chosen leaf input instead: keep using
  idx1/idx2 to select which side's sample to use, then ask that leaf
  input which part of the predicate it produces. The side and the key
  can no longer disagree.
- runSamplingQueryDistinct takes an ILogicalExpression overload that
  inserts an ASSIGN for a computed key. A bare variable reference builds
  the same plan as before, so existing estimates are unchanged.
- This also corrects a silent misestimate in the mirrored shape, where
  the computed expression is on the sampled side. There all variables
  are live, so nothing crashed, but the distinct count came from one
  column the expression reads rather than from the expression itself.

Tests:
- runtimets cbo-join/computed-join-predicate reproduces the compilation
  failure.
- runtimets cbo-join/computed-join-predicate-sampled-side step 5 pins
  the sampled-side estimate, which changed from 960 to 9600 against a
  true join cardinality of roughly 31000. It is a regex fixture rather
  than an exact plan. Seven suites run this case under five
  configurations, and an exact plan cannot hold across them: the sort
  shape depends on compiler.sort.parallel, since
  AttachCompileTimeRangeMapRule only attaches a range map when parallel
  sort is on and every data source under the ORDER subtree has a sample,
  which this test creates itself; and under compiler.parallelism=-1 the
  cost annotations scale with the runner's core count, which made the
  same query report three different total-cost values across CI and two
  workstations.
- cc-ssl.conf sets compiler.sort.parallel=false, matching cc.conf, the
  configuration the runtimets plan fixtures are generated under.
  SslSqlppExecutionTest constructs a no-arg TestExecutor, so it has no
  delta results directory and can only read results/.
- optimizerts cbo-join/computed-join-predicate.sqlpp covers the same
  shape at plan level; no optimizer fixture ran ANALYZE before, so the
  sampling path had no plan level coverage at all.
- OptimizerTest and CBOOptimizerTest both 702/702, no other plan moved.

Ext-ref: MB-73256

Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
Change-Id: I604d0ab81473b7be32dc2f098abfa122f3b52523
---
M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
M asterixdb/asterix-app/src/test/resources/cc-ssl.conf
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/cbo-join/computed-join-predicate.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/results/cbo-join/computed-join-predicate.plan
A asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/cbo-join/computed-join-predicate.plan
M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/CBOJoinQueries.xml
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/both-unnest-join/both-unnest-join.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/both-unnest-join/both-unnest-join.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/both-unnest-join/both-unnest-join.3.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/both-unnest-join/both-unnest-join.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/both-unnest-join/both-unnest-join.5.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.3.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.5.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate/computed-join-predicate.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate/computed-join-predicate.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate/computed-join-predicate.3.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cbo-join/computed-join-predicate/computed-join-predicate.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/cbo-join/both-unnest-join/both-unnest-join.4.regex
A asterixdb/asterix-app/src/test/resources/runtimets/results/cbo-join/both-unnest-join/both-unnest-join.5.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.4.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/cbo-join/computed-join-predicate-sampled-side/computed-join-predicate-sampled-side.5.regex
A asterixdb/asterix-app/src/test/resources/runtimets/results/cbo-join/computed-join-predicate/computed-join-predicate.4.adm
25 files changed, 1,143 insertions(+), 11 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/51/21551/7
-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21551?usp=email
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I604d0ab81473b7be32dc2f098abfa122f3b52523
Gerrit-Change-Number: 21551
Gerrit-PatchSet: 7
Gerrit-Owner: Ritik Raj <ri...@couchbase.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Ritik Raj <ri...@couchbase.com>
Gerrit-Attention: Ritik Raj <ri...@couchbase.com>