Repository navigation
[3.0-dev] Backport function/window compatibility (Fixes #24185) - #24194
Conversation
Fix the `ELT()` function to be fully compatible with MySQL.
**Root Cause:**
`eltCheck` skipped casting for integer types other than `int64` (e.g. `int32`, `int16`, `bool`), but the `Elt` executor hardcodes `GenerateFunctionFixedTypeParameter[int64]`, causing a type mismatch panic when using `INT`/`SMALLINT`/`TINYINT` columns or `BOOL` values as the index argument.
**Fix:**
In `eltCheck`, explicitly handle all numeric types (`bool`, `integer`, `float`, `decimal`, `bit`) by always casting the first argument to `int64`. For other types (e.g. `varchar`), fall back to `tryToMatch`.
**Test Coverage:**
Updated BVT tests (52 SQL statements) covering:
- INT/SMALLINT/TINYINT/UNSIGNED column as index (was panic)
- BOOL index: `ELT(TRUE, ...)` / `ELT(FALSE, ...)`
- Float index with rounding: `ELT(1.9, ...)` → 2
- String index: `ELT('2', ...)`
- Negative/zero float index
- Table with NULL index rows
- Table with out-of-range index rows
- BINARY return type
- Expression as index
- ELT + FIELD complement
- Removed all `@bvt:issue#22992` skip tags
Approved by: @heni02, @ouyuanning, @aunjgr
This PR implements a minimal MySQL-compatible AES_ENCRYPT/AES_DECRYPT enhancement aligned with block_encryption_mode. What changed: Added 3-argument overloads (AES_ENCRYPT(str, key, iv) / AES_DECRYPT(crypt, key, iv)) for varchar/char/text/blob inputs, returning blob/varchar as appropriate. Implemented MySQL-style XOR key folding and switched key derivation away from SHA1. Added AES-CBC support alongside the existing ECB path, gated by block_encryption_mode (aes-128-ecb default, aes-256-cbc supported). Enforced IV requirements for CBC (missing/short IV returns NULL, matching MySQL’s error-to-NULL behavior). Added focused tests for ECB/CBC roundtrip and CBC missing-IV behavior. Files touched: [func_binary.go](https://file+.vscode-resource.vscode-cdn.net/Users/moukeyu/.vscode/extensions/openai.chatgpt-0.4.67-darwin-x64/webview/#) [list_builtIn.go](https://file+.vscode-resource.vscode-cdn.net/Users/moukeyu/.vscode/extensions/openai.chatgpt-0.4.67-darwin-x64/webview/#) [func_binary_aes_test.go](https://file+.vscode-resource.vscode-cdn.net/Users/moukeyu/.vscode/extensions/openai.chatgpt-0.4.67-darwin-x64/webview/#) Test: go test ./pkg/sql/plan/function -count=1 Approved by: @ouyuanning, @heni02, @aunjgr
Backport of matrixorigin#23762 and matrixorigin#23764 to 3.0-dev, adapted to the older aggexec API on this branch (no SaveIntermediateResult / streaming serialization helpers, [][]int64 instead of []i64Slice, 3-return marshalToBytes / 2-arg unmarshalFromBytes / 4-arg initAggResultWithFixedTypeResult). CUME_DIST() returns the cumulative distribution of a value within a partition: (rows with values <= current row) / (total rows in partition). PERCENT_RANK() returns the relative rank of a row within a partition as a percentage: (rank - 1) / (total rows - 1). Co-authored-by: Copilot <[email protected]>
The earlier ELT cherry-pick (b130341) brought in a copy of func_binary_test.go from main that contains tests for TimeFormat, TimestampDiffDateString, TimestampDiffStringDate, etc.—functions that exist on main but not on 3.0-dev. It also forgot to register the ELT function id and overload, so 'elt(...)' resolution would fail. This commit: * Adds the ELT function id (348) and 'elt' name mapping. * Registers the ELT overload in list_builtIn.go bound to the existing Elt / eltCheck implementations from func_binary.go. * Updates function_id_test.go's predefined map. * Removes the main-only TimeFormat / TIMESTAMPDIFF / DATE_*_ADD test blocks that don't compile on 3.0-dev, while preserving the ELT-specific tests at the end of the file. Adds the 'vector' import needed by those preserved tests. Co-authored-by: Copilot <[email protected]>
|
|
This PR narrows the lock hold window for pessimistic `INSERT ... SELECT ...` statements that were escalated to table locks. Before this change, `Compile.prePipelineInitializer()` acquired the target table lock before the source side of the pipeline started running, which let large source scans hold the target table lock for too long and block later writers. The change keeps table-lock semantics intact but skips pre-pipeline table locking for `Query_INSERT`, allowing the existing `LockOp` in the execution pipeline to acquire the table lock closer to the actual write path. A focused compile test is added to lock the intended timing behavior. Approved by: @ouyuanning, @aunjgr, @XuPeng-SH
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking issue: state restoration for CUME_DIST() / PERCENT_RANK() is broken after serialization.
In pkg/sql/colexec/aggexec/window.go:301-309 and :446-454, unmarshal() guards the decode with if len(exec.groups) > 0 { ... }. During UnmarshalFromReader, though, a fresh executor starts with exec.groups == nil, so this branch never runs and the serialized groups payload is silently dropped.
Both executors depend on groups in Flush(), so any path that saves and restores intermediate state can produce wrong or empty window results for CUME_DIST() and PERCENT_RANK().
This should check len(groups) > 0 instead. Also, the new marshal/unmarshal tests only assert NoError; please make them verify that the restored executor actually preserves group state / produces the same output after unmarshal so this regression is covered.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head.
The previous blocking issue in pkg/sql/colexec/aggexec/window.go is fixed: both cumeDistWindowExec.unmarshal() and percentRankExec.unmarshal() now restore groups from the serialized payload correctly, and the updated tests in pkg/sql/colexec/aggexec/window_test.go now verify restored state and post-unmarshal results rather than only checking NoError.
I did not find any new PR-introduced blocking issues in the current revision.
Merge Queue Status
This pull request spent 31 minutes 8 seconds in the queue, with no time running CI. Waiting for:
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks HintYou may have to fix your CI before adding the pull request to the queue again. |
Merge Queue Status
This pull request spent 32 minutes 31 seconds in the queue, with no time running CI. Waiting for:
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks HintYou may have to fix your CI before adding the pull request to the queue again. |
Investigation findings: - Top-K optimization is already implemented and working correctly - Top operator uses heap algorithm with O(K) memory complexity - Verified via runtime logging: queries with LIMIT use Top operator - Memory usage is reasonable: ~520 bytes/row for heap storage - CI OOM is likely due to environment constraints, not code issue For 100M rows with LIMIT 5M: - Expected memory: ~2.6GB (acceptable) - Actual Top operator is used and memory efficient Recommendation: Investigate CI environment memory configuration rather than code changes, as the optimization already exists. Related: matrixorigin/mo-nightly-regression#25022702692
Merge Queue Status
This pull request spent 25 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
fixes #24185
What this PR does / why we need it:
ELT()MySQL compatibilityAES_ENCRYPT()/AES_DECRYPT()CUME_DIST()window functionPERCENT_RANK()window functionNotes on adaptation
CUME_DISTandPERCENT_RANKdid not cherry-pick cleanly because main'spkg/sql/colexec/aggexeclayer has been refactored substantially relativeto 3.0-dev (different signatures for
initAggResultWithFixedTypeResult,marshalToBytes,unmarshalFromBytes, plus newSaveIntermediateResult*/UnmarshalFromReaderinterface methods and ani64Slicetype).These two executors were rewritten to follow 3.0-dev's existing
singleWindowExecpattern ([][]int64groups, 3-returnmarshalToBytes,2-arg
unmarshalFromBytes, no streaming serialization). Algorithms matchthe originals exactly.
The ELT cherry-pick brought in a copy of
func_binary_test.gofrom maincontaining tests for
TimeFormat/TimestampDiffDateString/ etc. thatdon't exist on 3.0-dev. Those test blocks were removed; the ELT-specific
tests at the end of the file are preserved. Also added the
ELTfunctionid and overload registration that the cherry-pick didn't include.
Verification
all pass.
Fixes #24185