Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues. Searches for JSON_TABLE unused/pruned columns and
convertColumnfound no exact owner. [Compatibility]: MySQL JSON_TABLE syntax and relational expansion are unsupported #28036 covers unsupported JSON_TABLE syntax/expansion, not this executor path.
Branch Name
main
Commit ID
Other Environment Information
- Isolated single-node runtime; every formal run returned
git_version()='98b20975'andSELECT 42=42. GOMAXPROCS=4,GOMEMLIMIT=4GiB,max_dop=1; arms ran serially in owned disposable schemas.- Two formal scales, N=8,192 and N=16,384; 500 result-checked statements per arm under a 20-second symbolized CPU profile at each scale.
- Exact results, empty immediate
SHOW WARNINGS, executed physical plans, planner serialized-spec inspection, and schema cleanup passed at both scales. - This is a structural executor-path and sampled-CPU report, not a wall-clock-speedup claim.
Actual Behavior
A JSON_TABLE query whose only consumer-visible column is n FOR ORDINALITY still converts every column in the serialized table spec. In the target, the planner output attributes are exactly ["n"], but the spec is ["waste0","waste1","waste2","waste3","n"]; selected column n is at spec position 4. Four unselected conversions therefore remain in jsonTableState.nextRow.
The exact narrow control serializes only n. Both arms execute a single-worker physical tablefunction 0→N → group N→1 and return COUNT=N, SUM(n)=N(N+1)/2 with identical empty warnings.
Direct symbolized CPU attribution:
| N | Target json_table.go:296 (convertColumn call) |
Target json_table.go:239 (ConvertTablePathMatchesWithOptions) |
Control ordinary conversion |
|---|---|---|---|
| 8,192 | 6.68s cumulative | 5.75s cumulative | no samples |
| 16,384 | 6.20s cumulative | 5.46s cumulative | no samples |
The target's conversion work includes four columns that its own pruned output cannot expose. The control is a fixed-input upper bound, not a generally semantics-preserving rewrite for arbitrary JSON_TABLE error/warning policies.
Expected Behavior
When projection pruning proves that table-function outputs are unobservable, JSON_TABLE should avoid their ordinary conversion work where exact SQL semantics permit. Possible implementations include pruning the serialized spec during planning or lazily converting only selected outputs during execution.
The implementation must explicitly preserve column-position mapping, nested/ordinality behavior, ON EMPTY/ON ERROR actions, conversion errors and warnings, truncation policy, and cases where evaluating an unselected expression is observably required. This report does not request blindly dropping fallible conversions.
Steps to Reproduce
Use N=8,192 and then N=16,384. The following Python helper generates the two SQL statements; each JSON object has a 2 KiB waste string, keeping N=16,384 below the 64 MiB blob limit:
def json_query(arm, n):
waste = "" if arm == "control" else (
"waste0 VARCHAR(2048) PATH '$.waste',"
"waste1 TEXT PATH '$.waste',"
"waste2 BIGINT PATH '$.number',"
"waste3 DOUBLE PATH '$.number',"
)
obj = '{"number":1,"waste":"' + "x" * 2048 + '"}'
source = "CONCAT('[',REPEAT('" + obj + ",'," + str(n - 1) + "),'" + obj + "]')"
return (
"SELECT COUNT(*),SUM(jt.n) FROM JSON_TABLE(" + source +
",'$[*]' COLUMNS(" + waste + "n FOR ORDINALITY)) jt"
)Run both statements with SET max_dop=1, check the exact aggregate and immediate SHOW WARNINGS, and inspect:
EXPLAIN <query>;
EXPLAIN PHYPLAN ANALYZE <query>;For the planner gate, inspect the FUNCTION_SCAN node's TableDef.Cols and unmarshal TableDef.TblFunc.Param as jsonvalue.TableSpec. Require output columns ["n"] for both arms, target spec columns ["waste0","waste1","waste2","waste3","n"], and control spec columns ["n"]. An EXPLAIN-only projection check is insufficient because an earlier correlated fixture retained all five TableDef columns despite displaying only jt.n.
Profile each arm separately for 20 seconds while repeating the statement 500 times with exact result checks:
curl --fail --silent --show-error \
'http://127.0.0.1:16011/debug/pprof/profile?seconds=20' \
--output json-target.cpu.pprof
go tool pprof -list='table_function\.\(\*jsonTableState\)\.nextRow' \
./mo-service json-target.cpu.pprof
go tool pprof -list='table_function\.\(\*jsonTableState\)\.convertColumn' \
./mo-service json-target.cpu.pprofAt this commit, nextRow lines 292–296 iterates every non-nested spec column, and convertColumn line 239 performs path conversion.
Additional information
Evidence includes probe_day12_json_pruned.py, a read-only Go-overlay planner test, and complete plans/profiles/receipts under json_pruned_verified_n8192/ and json_pruned_verified_n16384/ in the local Day-12 investigation artifacts. No product source change was used for the runtime measurements.
Activity