Skip to content

Commit 10f6dfe

Browse files
author
Jan Wedvik
committed
Bug#36130806 EstimateDeleteRowsCost() Assertion failed: val >= 0.0 || 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
1 parent 4093c4d commit 10f6dfe

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

mysql-test/suite/json/r/json_table.result

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,3 +2196,26 @@ SELECT * FROM JSON_TABLE('[1, 2]', '$' COLUMNS (
21962196
#
21972197
SELECT 1 FROM JSON_TABLE(ROW(1, 2), '$' COLUMNS (o FOR ORDINALITY)) AS jt;
21982198
ERROR 21000: Operand should contain 1 column(s)
2199+
#
2200+
# Bug#36130806 EstimateDeleteRowsCost()
2201+
# Assertion failed: val >= 0.0 || val == kUnknownCost
2202+
#
2203+
CREATE TABLE t (c0 INT PRIMARY KEY);
2204+
INSERT INTO t VALUES (1),(2);
2205+
ANALYZE TABLE t;
2206+
Table Op Msg_type Msg_text
2207+
test.t analyze status OK
2208+
EXPLAIN FORMAT=TREE DELETE FROM t WHERE EXISTS
2209+
(
2210+
SELECT a FROM json_table('[{"a":"3"}]','$[0].a'
2211+
COLUMNS( a FOR ORDINALITY)
2212+
) as q
2213+
);
2214+
EXPLAIN
2215+
-> Delete from t (buffered) (rows=2)
2216+
-> Nested loop inner join (rows=2)
2217+
-> Limit: 1 row(s) (rows=1)
2218+
-> Materialize table function (rows=2)
2219+
-> Table scan on t (rows=2)
2220+
2221+
DROP TABLE t;

mysql-test/suite/json/t/json_table.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
--source include/elide_costs.inc
12
# For stable statistics
23
--source include/have_innodb_16k.inc
34
--echo #
@@ -1533,3 +1534,26 @@ SELECT * FROM JSON_TABLE('[1, 2]', '$' COLUMNS (
15331534
--echo #
15341535
--error ER_OPERAND_COLUMNS
15351536
SELECT 1 FROM JSON_TABLE(ROW(1, 2), '$' COLUMNS (o FOR ORDINALITY)) AS jt;
1537+
1538+
--echo #
1539+
--echo # Bug#36130806 EstimateDeleteRowsCost()
1540+
--echo # Assertion failed: val >= 0.0 || val == kUnknownCost
1541+
--echo #
1542+
1543+
CREATE TABLE t (c0 INT PRIMARY KEY);
1544+
1545+
INSERT INTO t VALUES (1),(2);
1546+
1547+
ANALYZE TABLE t;
1548+
1549+
# Do a 'delete' using a subquery with a table function.
1550+
--replace_regex $elide_costs
1551+
--skip_if_hypergraph # Depends on the query plan.
1552+
EXPLAIN FORMAT=TREE DELETE FROM t WHERE EXISTS
1553+
(
1554+
SELECT a FROM json_table('[{"a":"3"}]','$[0].a'
1555+
COLUMNS( a FOR ORDINALITY)
1556+
) as q
1557+
);
1558+
1559+
DROP TABLE t;

sql/sql_executor.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,8 @@ static AccessPath *GetTableAccessPath(THD *thd, QEP_TAB *qep_tab,
17651765
table_path = NewMaterializedTableFunctionAccessPath(
17661766
thd, qep_tab->table(), qep_tab->table_ref->table_function,
17671767
qep_tab->access_path());
1768+
1769+
CopyBasicProperties(*qep_tab->access_path(), table_path);
17681770
} else if (qep_tab->materialize_table == QEP_TAB::MATERIALIZE_SEMIJOIN) {
17691771
Semijoin_mat_exec *sjm = qep_tab->sj_mat_exec();
17701772

0 commit comments

Comments
 (0)