Skip to content

Commit

Permalink
Bug#36130806 EstimateDeleteRowsCost() Assertion failed: val >= 0.0 ||…
Browse files Browse the repository at this point in the history
… val == kUnknownCost

This commit ensures that we set the cost of AccessPath objects of type
MATERIALIZED_TABLE_FUNCTION. That cost can then be used as input for
cost calculations higher up in the AccessPath tree.

Change-Id: If11f0df40a1cc3b7cb360f1c88f5b7449c07a8d2
  • Loading branch information
Jan Wedvik committed Feb 6, 2024
1 parent 4093c4d commit 10f6dfe
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mysql-test/suite/json/r/json_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -2196,3 +2196,26 @@ SELECT * FROM JSON_TABLE('[1, 2]', '$' COLUMNS (
#
SELECT 1 FROM JSON_TABLE(ROW(1, 2), '$' COLUMNS (o FOR ORDINALITY)) AS jt;
ERROR 21000: Operand should contain 1 column(s)
#
# Bug#36130806 EstimateDeleteRowsCost()
# Assertion failed: val >= 0.0 || val == kUnknownCost
#
CREATE TABLE t (c0 INT PRIMARY KEY);
INSERT INTO t VALUES (1),(2);
ANALYZE TABLE t;
Table Op Msg_type Msg_text
test.t analyze status OK
EXPLAIN FORMAT=TREE DELETE FROM t WHERE EXISTS
(
SELECT a FROM json_table('[{"a":"3"}]','$[0].a'
COLUMNS( a FOR ORDINALITY)
) as q
);
EXPLAIN
-> Delete from t (buffered) (rows=2)
-> Nested loop inner join (rows=2)
-> Limit: 1 row(s) (rows=1)
-> Materialize table function (rows=2)
-> Table scan on t (rows=2)

DROP TABLE t;
24 changes: 24 additions & 0 deletions mysql-test/suite/json/t/json_table.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--source include/elide_costs.inc
# For stable statistics
--source include/have_innodb_16k.inc
--echo #
Expand Down Expand Up @@ -1533,3 +1534,26 @@ SELECT * FROM JSON_TABLE('[1, 2]', '$' COLUMNS (
--echo #
--error ER_OPERAND_COLUMNS
SELECT 1 FROM JSON_TABLE(ROW(1, 2), '$' COLUMNS (o FOR ORDINALITY)) AS jt;

--echo #
--echo # Bug#36130806 EstimateDeleteRowsCost()
--echo # Assertion failed: val >= 0.0 || val == kUnknownCost
--echo #

CREATE TABLE t (c0 INT PRIMARY KEY);

INSERT INTO t VALUES (1),(2);

ANALYZE TABLE t;

# Do a 'delete' using a subquery with a table function.
--replace_regex $elide_costs
--skip_if_hypergraph # Depends on the query plan.
EXPLAIN FORMAT=TREE DELETE FROM t WHERE EXISTS
(
SELECT a FROM json_table('[{"a":"3"}]','$[0].a'
COLUMNS( a FOR ORDINALITY)
) as q
);

DROP TABLE t;
2 changes: 2 additions & 0 deletions sql/sql_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,8 @@ static AccessPath *GetTableAccessPath(THD *thd, QEP_TAB *qep_tab,
table_path = NewMaterializedTableFunctionAccessPath(
thd, qep_tab->table(), qep_tab->table_ref->table_function,
qep_tab->access_path());

CopyBasicProperties(*qep_tab->access_path(), table_path);
} else if (qep_tab->materialize_table == QEP_TAB::MATERIALIZE_SEMIJOIN) {
Semijoin_mat_exec *sjm = qep_tab->sj_mat_exec();

Expand Down

0 comments on commit 10f6dfe

Please sign in to comment.