Skip to content

fix: handle BenchBase metadata and lockop fallback - #27244

Merged
mergify[bot] merged 27 commits into
matrixorigin:mainfrom
daviszhen:agent/fix-benchbase-lockop
Aug 20, 2026
Merged

mergify[bot] merged 27 commits into
matrixorigin:mainfrom
daviszhen:agent/fix-benchbase-lockop

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #27242

#25103

What this PR does / why we need it:

  1. 修复 BenchBase/JDBC 元数据查询

    • 允许 MySQL 兼容模式下,ONLY_FULL_GROUP_BY 查询中的非聚合 HAVING 过滤。
    • MATRIXONE_NATIVE 模式仍保持严格校验。
    • 新增 Connector/J DatabaseMetaData.getTables() 的 UT 和 BVT。
  2. 修复 LockOp 空指针 panic

    • 当共享锁合并路径未初始化版本范围检查器时,使用默认检查函数,避免 BenchBase/AuctionMark 批量插入触发 nil pointer。
    • 新增合并锁目标回归测试。

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review completed on exact head 542276392bd2396073118c5bc004978b759105a1. The LockOp fallback and the non-aggregate HAVING planner change are sound, and focused lockop / planner tests pass. One fixture blocker remains:

  • [P2] Preserve the empty REMARKS value in the new BVT result. test/distributed/cases/metadata/mysql_compat_jdbc_get_tables.result records null immediately after TABLE for both rows, but a table created without a comment has a non-null empty rel_comment: catalog insertion appends schema.Comment with isNull=false, and information_schema.TABLES.TABLE_COMMENT is cast(rel_comment as text). The existing equivalent Connector/J-shaped result in test/distributed/cases/pessimistic_transaction/create_table.result therefore has an empty field (eight spaces between TABLE and the first null). The new BVT will produce that same empty REMARKS, so these two expected rows will mismatch. Update both rows to keep the empty field before the five trailing null columns (or regenerate the result from the test runner).

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking findings on f3039c9:

  1. [P1] pkg/sql/plan/having_binder.go:131 binds every column in a non-aggregate HAVING directly against the query input. That bypasses projected-alias resolution, which is exactly what the Connector/J query needs. On an exact-head local MatrixOne instance, the new BVT query returns zero rows: HAVING TABLE_TYPE = 'TABLE' sees the source value information_schema.tables.TABLE_TYPE = 'BASE TABLE', not the projected CASE alias value TABLE. The two created tables are therefore filtered out. The planner-only test merely checks that planning succeeds and never executes the query, so it misses this failure.

    The branch also broadens MySQL compatibility incorrectly: with ONLY_FULL_GROUP_BY, exact head accepts SELECT n_regionkey FROM nation HAVING n_nationkey > 0; the same harness rejects it on base 4aab5da, and MySQL 8.4 rejects the equivalent query with ERROR 1054 Unknown column 'b' in 'having clause'. Please preserve HAVING's alias/visibility rules and relax only the grouping restriction needed for a resolved projected alias, then add execution-level positive and negative regressions.

  2. [P1] test/distributed/cases/metadata/mysql_compat_jdbc_get_tables.result:31-32 records REMARKS as null, but an exact-head instance returns a non-null empty TABLE_COMMENT (IF(TABLE_COMMENT IS NULL, 'IS_NULL', CONCAT('[', TABLE_COMMENT, ']')) produced [] for both tables). Once the alias-binding issue is fixed and rows are returned, these expectations will still fail. The existing JDBC metadata fixture under pessimistic_transaction/create_table.result also represents this field as empty. Please regenerate the result from a real BVT run.

Validation performed: exact-head package binaries for pkg/sql/plan and pkg/sql/colexec/lockop; full lockop tests passed; targeted new planner/lockop tests passed; go vet passed for both packages; exact-head mo-service execution exposed the two failures above. Q1-Q3 lifecycle audit found no new cleanup, wait-for, or unbounded-growth defect in the lockop change.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Deep re-review of exact head 8fd8fd8a51a18188346bc7e0f595839eb6b993c7 found two merge blockers.

P1: Do not treat an anonymous repeated expression as a HAVING-visible output

SELECT a+1 FROM t HAVING a+1>1 is accepted by this head, while MySQL 8.4.10 rejects it with Unknown column 'a' in 'having clause' under ONLY_FULL_GROUP_BY; the exact base also rejects it.

In pkg/sql/plan/having_binder.go, BindExpr/isProjectedOutputExpr marks a HAVING subtree as bindingProjectedAlias merely because it is semantically equal to a SELECT expression. The recursive binder then lets the source columns inside that anonymous expression bypass visibility validation. An anonymous expression has no output name that HAVING can resolve. Only an expression reached through a real projected output name/slot should receive this exemption; AST equality alone is insufficient. Please add a negative planner/execution regression (the defect also affects forms such as ABS(a)).

P2: Reject ambiguous duplicate HAVING aliases instead of silently selecting the last one

SELECT a AS x, b AS x FROM t HAVING x>0 is accepted and silently binds x to b on this head. MySQL 8.4.10 reports Column 'x' in having clause is ambiguous; the exact base rejects it.

query_builder.go overwrites aliasMap[x] while recording aliasFrequency[x], but the AliasBeforeColumn path in bind_context.go returns the last map entry without checking ambiguity. Please apply the same semantic ambiguity contract used by the ORDER/GROUP resolution paths and add both regressions: different expressions must be ambiguous, while SELECT a AS x, a AS x ... HAVING x>0 remains valid.

The LockOp changes passed the correctness/lifecycle review and targeted race tests; they are not part of this request for changes.

  • 支持 HAVING t.a 匹配直接投影的 t.a,包括带别名的直接投影。
  • a + 1 AS x 等表达式投影仍不会放行 HAVING t.a。
  • 增加限定列名正负回归及 BVT 用例。

@daviszhen

Copy link
Copy Markdown
Contributor Author

Deep re-review of exact head eb8295b, including the prior review history. The latest commit fixes the anonymous-expression equality case and duplicate-alias ambiguity, but one output-visibility edge remains.

[P1] Preserve qualified references to directly projected columns in HAVING under ONLY_FULL_GROUP_BY.

MySQL accepts both SELECT t.a FROM t HAVING t.a > 0 and SELECT a AS x FROM t HAVING t.a > 0 when a is a directly projected source column. The current HavingBinder.BindColRef consults havingOutputExpr only when NumParts == 1; a qualified reference such as nation.n_regionkey bypasses output visibility and falls through to the GROUP BY / functional-dependency check, so the equivalent query is rejected even though that exact column is projected.

I reproduced this on this exact head with a temporary planner regression:

SELECT nation.n_regionkey
FROM nation
HAVING nation.n_regionkey > 0

It fails with column "nation.n_regionkey" must appear in the GROUP BY clause or be used in an aggregate function. The checked-in HAVING tests otherwise pass.

Please make qualified column refs participate in the direct-projection visibility check while retaining the intended boundary: SELECT a + 1 AS x FROM t HAVING t.a > 0 must remain rejected because a is only embedded in an anonymous expression. Please add positive qualified/unqualified direct-projection controls and that negative anonymous-expression control.

  • 支持 HAVING t.a 匹配直接投影的 t.a,包括带别名的直接投影。
  • a + 1 AS x 等表达式投影仍不会放行 HAVING t.a。
  • 增加限定列名正负回归及 BVT 用例。

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest fixes cover the previously reported alias/direct-column cases, but equivalent database qualification is still rejected.

Comment thread pkg/sql/plan/bind_context.go Resolved
@daviszhen

Copy link
Copy Markdown
Contributor Author

The latest fixes cover the previously reported alias/direct-column cases, but equivalent database qualification is still rejected.

  • havingProjectedColumnExpr 改为按绑定身份(关系 tag + 列位置)判断列是否等价,支持 nation.col 与 tpch.nation.col 双向引用。
  • 新增数据库限定符回归测试。

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head 5b5ef77. The non-aggregate HAVING visibility rules now distinguish projected aliases, direct projected columns, anonymous expressions, duplicate aliases, and qualified references by resolved binding identity; the latest database-qualification cases close the prior blocker. LockOp fallback/shared-target behavior and the JDBC metadata regressions are covered, and all checks pass. No additional blocking finding.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head 5b5ef776a0300947301c952247ec44560f2ec98d, including all prior feedback. The latest qualification fix closes the previously reported database-qualified case, but output-name resolution still has two MySQL compatibility gaps:

  1. [P1] Treat explicit/implicit duplicate output names as ambiguous. havingOutputExpr returns immediately after finding an explicit alias and never checks unaliased direct projections with the same output name. Consequently, exact head accepts SELECT n_nationkey AS n_regionkey, n_regionkey FROM nation HAVING n_regionkey > 0 and silently binds HAVING to n_nationkey. MySQL 8.4.11 rejects the equivalent SELECT b AS a, a FROM t HAVING a > 0 with ERROR 1052: Column 'a' in having clause is ambiguous. The checked-in duplicate tests cover explicit/explicit aliases only. Please include implicit output names in the ambiguity set while retaining explicit-alias precedence over a source column that is not separately projected.

  2. [P2] Preserve the implicit output name for unary-plus column projections. MySQL 8.4.11 accepts SELECT +a FROM t HAVING a > 0 under ONLY_FULL_GROUP_BY (the output name is a). Exact head rejects the equivalent SELECT +n_regionkey FROM nation HAVING n_regionkey > 0 because only a bare/parenthesized UnresolvedName is recognized as an implicit output. Please normalize this no-op wrapper, or otherwise derive the projected output name consistently with MySQL, and add a regression.

Both counterexamples were reproduced in a temporary exact-head planner test; the first unexpectedly returned no error and the second failed with the GROUP BY error. The LockOp changes remain sound under the earlier lifecycle/Q1-Q3 review.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head 5b5ef776a0300947301c952247ec44560f2ec98d. The two findings from my previous review are closed, but output-name resolution is still incomplete.

P1: explicit and implicit outputs with the same name must participate in one ambiguity set

pkg/sql/plan/bind_context.go:722-758 first scans explicit aliases and returns immediately at lines 738-740 if any exist; it scans implicit direct-column output names only when there was no explicit match. Therefore this head accepts and silently resolves:

SELECT b AS a, a FROM t HAVING a > 0;

to b AS a. MySQL rejects it because the SELECT list exposes two different outputs named a; explicit-alias precedence over an unprojected source column does not make a separately projected a disappear. The current duplicate tests cover only explicit/explicit aliases. Build a single candidate set across explicit and implicit output names, reject semantically different matches, and retain the existing allowance for equivalent duplicates.

P2: preserve MySQL's implicit output name through unary plus

The implicit-name scan only recognizes unwrapParenExpr(field.ast).(*tree.UnresolvedName) at lines 742-748. Consequently SELECT +a FROM t HAVING a > 0 is rejected under ONLY_FULL_GROUP_BY, although unary plus preserves the column's implicit output name and MySQL accepts this form. Normalize this no-op wrapper when deriving output names (without making arbitrary anonymous expressions visible) and add a regression alongside the parenthesized/direct-column cases.

The anonymous-expression and explicit/explicit-alias blockers from the prior head are fixed. The LockOp portion remains sound under the earlier ownership/wait-for review.

@daviszhen

Copy link
Copy Markdown
Contributor Author

已修复最新 review 中的两个 planner 问题,并合并最新 upstream/main。

  • HAVING 输出名解析现在统一收集显式别名和隐式直接列名:不同表达式使用同名时返回 ambiguous;语义等价的显式/隐式重复投影仍允许;显式别名仍优先于未投影的源列。
  • 对直接列的无操作一元 + 保留隐式输出列名,因此 SELECT +n_regionkey ... HAVING n_regionkey ... 可正常绑定。
  • 新增 4 个 planner 回归测试覆盖上述冲突、等价重复、别名优先和一元加号场景。
  • 已合并 upstream/main(包含 e43d63edb),并推送新 head e9b12676d1c4a9e50f36ba08c6357eef26fea7e7。本地 go test ./pkg/sql/plan ./pkg/sql/colexec/lockop -count=1 通过。

请基于新 head 再次 review,谢谢。

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review completed against exact head e9b12676d1c4a9e50f36ba08c6357eef26fea7e7. The prior explicit/implicit collision and single-unary-plus cases are improved, but unary-plus normalization is still inconsistent across equivalent output matching, qualified projections, and nested no-op expressions. I reproduced the counterexamples locally and compared them with MySQL 9.6.0 under ONLY_FULL_GROUP_BY.

Comment thread pkg/sql/plan/bind_context.go Resolved
@daviszhen

Copy link
Copy Markdown
Contributor Author

已根据最新 review 修复 unary-plus 一致性问题,并合并最新 upstream/main(0d52788ac5)。

  • 新增递归的括号/一元 + 规范化,仅把直接列投影识别为 HAVING 可见输出;a+1 等匿名表达式仍不会暴露源列。
  • 输出等价判断和限定列投影查找统一使用规范化后的直接列绑定身份,覆盖 ++n_regionkey、+nation.n_regionkey 以及 +n_regionkey AS n_regionkey 与 n_regionkey 的等价重复投影。
  • 新增 3 个 planner 回归测试。
  • 本地通过:go test ./pkg/sql/plan ./pkg/sql/colexec/lockop -count=1,PR diff git diff --check 通过。
  • 新 head:cdcb5e4819afdad53622e4716b85096dd6da23d7,已推送。

请基于新 head 再次 review,谢谢。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review completed on exact head cdcb5e4. The current implementation closes the prior HAVING blockers: anonymous expressions do not gain output visibility, explicit and implicit duplicate names share one ambiguity set, qualified references compare resolved binding identity, and parentheses/recursive unary plus use one normalized direct-column identity without broadening arbitrary expressions. The JDBC alias case and updated direct-projection result baselines are consistent with those rules. No new blocking correctness, lifecycle, or complexity issue found. Validation: all focused positive/negative HAVING cases under -race -count=20, full pkg/sql/plan, and diff hygiene passed.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review completed on exact head 73c8280 against base c6b2ac9. I read the complete review/comment/thread history, checked the increment since the previously reviewed heads and re-audited the full diff. The prior HAVING visibility, ambiguity, qualification, and unary-plus normalization issues are closed, including the current merge resolution, and I found no new blocker. Validation: git diff --check; make thirdparties; make cgo; go test -count=1 -timeout=300s ./pkg/sql/plan.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review completed on exact head 73c8280e71a5a362157d928421f72138e372ffa5 against base c6b2ac9c1eaff0db867e845723a8ce1d2102928f. The previous alias/ambiguity/qualification/unary-plus findings are closed, but one concrete MySQL compatibility blocker remains in the new non-aggregate HAVING resolution. I reproduced it both with an exact-head planner regression and against a disposable MySQL 8.0.26 oracle under ONLY_FULL_GROUP_BY; details and the required positive/negative boundary are in the inline comment. The current Linux UT failure is Test_UpgradeEntry timing out in logservice startup and does not appear related to this planner diff, so it is not part of this request for changes.

Comment thread pkg/sql/plan/bind_context.go Resolved
@daviszhen

Copy link
Copy Markdown
Contributor Author

Fixed the remaining P1 in commit 7be88531b.

  • HavingBinder.BindColRef now falls back, after output-name lookup, to the resolved source identity for an unqualified column when that source is directly projected under a different alias (SELECT a AS x ... HAVING a).
  • Alias precedence and duplicate-output ambiguity are unchanged.
  • Unprojected sources (HAVING b) and sources embedded in an expression (SELECT a + 1 AS x ... HAVING a) remain rejected under ONLY_FULL_GROUP_BY.
  • Added the requested positive and negative regressions in pkg/sql/plan/build_test.go.

Validation:

  • go test ./pkg/sql/plan -count=1
  • targeted go test -race ./pkg/sql/plan for the full-group-by regressions
  • git diff --check

The previous Ubuntu UT failure (TestBasicCluster, TestIssue26882ComQueryCacheTracksViewIdentity, and Test_UpgradeEntry) was caused by logservice/Dragonboat startup timeouts in job 96298013277, before any planner assertion, and is unrelated to this change. This push should trigger a fresh check run. Please re-review the new head.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Follow-up commit d281ed286 adds an ambiguity guard for the same path: an unqualified source name recorded as ambiguous is no longer resolved through the spelling fallback to one projected table column. A regression now verifies SELECT n1.n_regionkey AS region_key ... JOIN nation n2 ... HAVING n_regionkey > 0 remains an ambiguous column reference under ONLY_FULL_GROUP_BY.

The targeted planner tests (including -race) pass, and the branch is clean. Please review the latest head d281ed286.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review completed on exact head ffcb0fd against base d7899e7. The prior unqualified projected-source blocker is fixed by resolving output names first and then matching a directly projected source by binding identity; the follow-up ambiguity guard preserves multi-table ambiguous-column errors. I re-audited the full current diff and found no new blocking correctness, compatibility, lifecycle, or complexity issue. Validation: git diff --check; exact-head CGo rebuild; GOWORK=off package selection/build/vet; 29 focused ONLY_FULL_GROUP_BY/native-boundary tests; full pkg/sql/plan; latest GitHub CI green.

@mergify

mergify Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-20 12:25 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-20 19:21 UTC · at 84c95c39c984a302fbd571b1380dc9cdcb9cc28c · squash

This pull request spent 6 hours 56 minutes 52 seconds in the queue, including 48 minutes 53 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants