From 0a7d2917568301ac0ad7af8af26278fba8060fe8 Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 9 Jan 2023 16:34:12 +0200 Subject: [PATCH] MDEV-30328 Assertion `avg_io_cost != 0.0 || index_cost.io + row_cost.io == 0' failed in Cost_estimate::total_cost() The assert was there to check that engines reports sensible numbers for IO. However this does not work in case of optimizer_disk_read_ratio=0. Fixed by removing the assert. --- mysql-test/main/costs.result | 35 +++++++++++++++++++++++++++++ mysql-test/main/costs.test | 43 +++++++++++++++++++++++++++++++++++- sql/handler.h | 3 --- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/costs.result b/mysql-test/main/costs.result index 2924c4c6d383e..9d69207f95602 100644 --- a/mysql-test/main/costs.result +++ b/mysql-test/main/costs.result @@ -89,3 +89,38 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range d d 5 NULL 2 Using index condition Last_query_cost 0.003291 drop table t1; +# +# MDEV-30328 Assertion `avg_io_cost != 0.0 || index_cost.io + row_cost.io == 0' failed in +# Cost_estimate::total_cost() +# +set @save=@@InnoDB.optimizer_disk_read_ratio; +set global InnoDB.optimizer_disk_read_ratio=0; +create table t1 ( +`l_orderkey` int(11) NOT NULL, +`l_partkey` int(11) DEFAULT NULL, +`l_suppkey` int(11) DEFAULT NULL, +`l_linenumber` int(11) NOT NULL, +`l_extra` int(11) NOT NULL, +`l_quantity` double DEFAULT NULL, +`l_extendedprice` double DEFAULT NULL, +`l_discount` double DEFAULT NULL, +`l_tax` double DEFAULT NULL, +`l_returnflag` char(1) DEFAULT NULL, +`l_linestatus` char(1) DEFAULT NULL, +`l_shipDATE` date DEFAULT NULL, +`l_commitDATE` date DEFAULT NULL, +`l_receiptDATE` date DEFAULT NULL, +`l_shipinstruct` char(25) DEFAULT NULL, +`l_shipmode` char(10) DEFAULT NULL, +`l_comment` varchar(44) DEFAULT NULL, +PRIMARY KEY (`l_orderkey`), +UNIQUE (`l_linenumber`), +UNIQUE (`l_extra`) , +KEY `l_suppkey` (l_suppkey, l_partkey), +KEY `long_suppkey` (l_partkey, l_suppkey, l_linenumber, l_extra) ) +ENGINE= InnoDB; +explain select count(*) from test.t1 force index (l_suppkey) where l_suppkey >= 0 and l_partkey >=0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range l_suppkey l_suppkey 10 NULL 1 Using where; Using index +drop table t1; +set global InnoDB.optimizer_disk_read_ratio=@save; diff --git a/mysql-test/main/costs.test b/mysql-test/main/costs.test index 6dcc41b57a332..bb933a200db04 100644 --- a/mysql-test/main/costs.test +++ b/mysql-test/main/costs.test @@ -1,8 +1,12 @@ # -# Test of cost calcuations. This test is using the Aria engine as the cost +# Test of cost calculations. This test is using the Aria engine as the cost # calculations are stable for it. # +# This file also includes MDEV's that shows errors in cost calculation functions. +# + --source include/have_sequence.inc +--source include/have_innodb.inc create table t1 (a int primary key, b int, c int, d int, e int, key ba (b,a), key bda (b,d,a), key cba (c,b,a), key cb (c,b), key d (d)) engine=aria; insert into t1 select seq,seq,seq,seq,seq from seq_1_to_10; @@ -73,3 +77,40 @@ explain select a,b,e from t1 where d=10 or d=11; --source include/last_query_cost.inc drop table t1; + +--echo # +--echo # MDEV-30328 Assertion `avg_io_cost != 0.0 || index_cost.io + row_cost.io == 0' failed in +--echo # Cost_estimate::total_cost() +--echo # + +set @save=@@InnoDB.optimizer_disk_read_ratio; +set global InnoDB.optimizer_disk_read_ratio=0; + +create table t1 ( + `l_orderkey` int(11) NOT NULL, + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL, + `l_extra` int(11) NOT NULL, + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + PRIMARY KEY (`l_orderkey`), + UNIQUE (`l_linenumber`), + UNIQUE (`l_extra`) , + KEY `l_suppkey` (l_suppkey, l_partkey), + KEY `long_suppkey` (l_partkey, l_suppkey, l_linenumber, l_extra) ) + ENGINE= InnoDB; +explain select count(*) from test.t1 force index (l_suppkey) where l_suppkey >= 0 and l_partkey >=0; +drop table t1; + +set global InnoDB.optimizer_disk_read_ratio=@save; diff --git a/sql/handler.h b/sql/handler.h index 209cb527716c9..41bc50e52d4d1 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -2834,7 +2834,6 @@ class Cost_estimate double total_cost() const { - DBUG_ASSERT(avg_io_cost != 0.0 || index_cost.io + row_cost.io == 0); return ((index_cost.io + row_cost.io) * avg_io_cost+ index_cost.cpu + row_cost.cpu + comp_cost + copy_cost + cpu_cost); @@ -2843,7 +2842,6 @@ class Cost_estimate /* Cost for just fetching and copying a row (no compare costs) */ double fetch_cost() const { - DBUG_ASSERT(avg_io_cost != 0.0 || index_cost.io + row_cost.io == 0); return ((index_cost.io + row_cost.io) * avg_io_cost+ index_cost.cpu + row_cost.cpu + copy_cost); } @@ -2875,7 +2873,6 @@ class Cost_estimate void add(Cost_estimate *cost) { - DBUG_ASSERT(cost->avg_io_cost != 0.0 || (index_cost.io + row_cost.io == 0)); avg_io_cost= cost->avg_io_cost; index_cost.io+= cost->index_cost.io; index_cost.cpu+= cost->index_cost.cpu;