Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  costs.test  Sprache: unbekannt

 
Spracherkennung für: .test vermutete Sprache: SQL {SQL[150] ABAP[120] Masm[100]} [Methode: maximale Elemente, drei Dimensionen]

#
# 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
--source include/innodb_stable_estimates.inc
--disable_replay testfile Uses Last_query_cost for most queries

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;
insert into t1 values(20,2,2,2,2),(21,3,4,5,6);

--echo #
--echo # Get different scan costs
--echo #

explain select sum(e) as "table_scan" from t1;
--source include/last_query_cost.inc
explain select sum(a) as "index scan" from t1;
--source include/last_query_cost.inc

--echo #
--echo # Range scans should be used if we don't examine all rows in the table
--echo #
explain select count(a) from t1;
--source include/last_query_cost.inc
explain select count(*) from t1 where a > 0;
--source include/last_query_cost.inc
explain select count(*) from t1 where a > 1;
--source include/last_query_cost.inc
explain select count(*) from t1 where a > 2;
--source include/last_query_cost.inc

--echo #
--echo # Shorter indexes are preferred over longer indexes
--echo #
explain select sum(a+b) from t1;
--source include/last_query_cost.inc
explain select count(*) from t1 where b between 5 and 10;
--source include/last_query_cost.inc
explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6;
--source include/last_query_cost.inc

--echo # Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd'
explain select count(*) from t1 where b > 6;
--source include/last_query_cost.inc
explain select count(*) from t1 where d > 6;
--source include/last_query_cost.inc


--echo #
--echo # Check covering index usage
--echo #
explain select a,b,c from t1 where a=b;
--source include/last_query_cost.inc

--echo #
--echo # Prefer ref keys over ranges
--echo #

explain select count(*) from t1 where b=2;
--source include/last_query_cost.inc
explain select count(*) from t1 where b=2 and c=2;
--source include/last_query_cost.inc
explain select count(*) from t1 where b=3 and c between 3 and 4;
--source include/last_query_cost.inc

--echo #
--echo # Prefer eq keys over ref keys
--echo #

explain select a,b,e from t1 where a=10 or a=11;
--source include/last_query_cost.inc
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;

--echo #
--echo # MDEV-37723 In MDEV-36861, analyze Q4
--echo # Alter disk based tmp table lookup cost formula
--echo #

create table t1 (a int primary key,
                 b date, c char(15),
                 d blob,
                 key t1_ix1 (b)) ENGINE= InnoDB;
create table t2 (e int not null,
                 f int not null,
                 g date, h date,
                 primary key (e, f)) ENGINE= InnoDB;
--disable_warnings
insert into t1 select seq, date('1993-06-01') + interval seq second,
  chr(65+mod(seq, 4)), NULL from seq_1_to_7000;
insert into t2 select a.seq, b.seq, date('1993-06-01') + interval b.seq day,
  if (mod(a.seq,2), date('1993-06-01') + interval b.seq+1 day,
    date('1993-06-01') - interval b.seq-1 day)
  from seq_1_to_7000 a, seq_1_to_3 b;

set
  @save_mhts= @@max_heap_table_size,
  @@max_heap_table_size=16384;


--echo # This should use "t1, FirstMatch(t2)".  Not "t1, SJ-Materialization(t2)".
explain format=json
select c, count(*) as dc
from t1
where
  b >= date '1993-06-01' and b < date '1993-06-01' + interval '3' month and
  exists (select * from t2 where e = t1.a and g < h)
group by c;

set max_heap_table_size=@save_mhts;
drop table t1, t2;

[Dauer der Verarbeitung: 0.12 Sekunden, vorverarbeitet 2026-10-08]

                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1126438
#Domains=1867298