diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 83fa5a9f2a00..7a04fe20d122 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -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; diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index 540c8fdfbad9..72fd24379e1e 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -1,3 +1,4 @@ +--source include/elide_costs.inc # For stable statistics --source include/have_innodb_16k.inc --echo # @@ -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; diff --git a/sql/sql_executor.cc b/sql/sql_executor.cc index 102585ebafb9..faf8fdbbacdc 100644 --- a/sql/sql_executor.cc +++ b/sql/sql_executor.cc @@ -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();