Quelle order_by_group_by_subst.result
Sprache: Lisp
#
# MDEV-36132 Optimizer support for functional indexes: handle GROUP/ORDER BY
#
create table t (c int, key (c));
insert into t select seq from seq_1_to_10000;
alter table t
add column vc bigint as (c + 1),
add index(vc);
explain select c from t order by c;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index
explain select vc from t order by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10000 Using index
explain select vc from t order by vc limit 10;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10 Using index
explain select c + 1 from t order by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using filesort
explain select c + 1 from t order by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using filesort
explain select vc from t order by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10000 Using index
explain select vc from t order by c;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index
explain select c from t order by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using filesort
explain select c from t order by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using filesort
explain select vc from t order by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2 Using index
explain select c + 1 from t order by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2
explain select c + 1 from t order by vc limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2
explain delete from t order by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2
alter table t add column d int;
explain update t set d = 500 order by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2 Using buffer
explain update t set d = 500 order by c limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 2 Using buffer
explain update t set c = 500 order by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2 Using buffer
explain update t set c = 500 order by c limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 2 Using buffer
drop table t;
create table t (c int);
insert into t select seq from seq_1_to_10000;
alter table t
add column vc bigint as (c + 1),
add index(vc);
explain select vc from t order by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10000 Using index
explain select vc from t order by c + 1 limit 10;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10 Using index
drop table t;
create table t (c int, key (c));
insert into t select seq from seq_1_to_10000;
alter table t
add column vc1 int as (c + 1),
add index(vc1);
alter table t
add column vc2 bigint as (vc1 * 2),
add index(vc2);
explain select c from t order by vc2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using filesort
explain select vc2 from t order by vc1 * 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc2 9 NULL 10000 Using index
explain select vc2 from t order by vc1 * 2 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc2 9 NULL 2 Using index
drop table t;
create table t (c int, vc int generated always as (1 + 1) virtual, key (c));
insert into t values (42, default), (83, default);
explain select vc from t order by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 2 Using index; Using filesort
select vc from t order by vc;
vc 2 2
drop table t;
create table t (c int);
insert into t select seq from seq_1_to_10000;
alter table t
add column vc1 bigint as (c + 1);
alter table t
add column vc2 bigint as (1 - c),
add index(vc1, vc2);
explain select vc1, vc2 from t order by c + 1, 1 - c;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc1 18 NULL 10000 Using index
drop table t;
create table t (c int, key (c));
insert into t select seq from seq_1_to_10000;
alter table t
add column vc bigint as (c + 1),
add index(vc);
explain select c from t group by c;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index
explain select vc from t group by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10000 Using index
explain select vc from t group by vc limit 10;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10 Using index
explain select c + 1 from t group by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using temporary; Using filesort
explain select c + 1 from t group by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using temporary; Using filesort
explain select vc from t group by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10000 Using index
explain select vc from t group by c;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index
explain select c from t group by vc;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using temporary; Using filesort
explain select c from t group by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using temporary; Using filesort
explain select vc from t group by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2 Using index
explain select c + 1 from t group by c + 1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2
explain select c + 1 from t group by vc limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 2
drop table t;
create table t (c int);
insert into t select seq from seq_1_to_10000;
alter table t
add column vc bigint as (c + 1),
add index(vc);
explain select vc from t group by c + 1;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10000 Using index
explain select vc from t group by c + 1 limit 10;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc 9 NULL 10 Using index
drop table t;
create table t (c int, key (c));
insert into t select seq from seq_1_to_10000;
alter table t
add column vc1 int as (c + 1),
add index(vc1);
alter table t
add column vc2 bigint as (vc1 * 2),
add index(vc2);
explain select c from t group by vc2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL c 5 NULL 10000 Using index; Using temporary; Using filesort
explain select vc2 from t group by vc1 * 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc2 9 NULL 10000 Using index
explain select vc2 from t group by vc1 * 2 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc2 9 NULL 2 Using index
drop table t;
create table t (c int);
insert into t select seq from seq_1_to_10000;
alter table t
add column vc1 bigint as (c + 1);
alter table t
add column vc2 bigint as (1 - c),
add index(vc1, vc2);
explain select vc1, vc2 from t group by c + 1, 1 - c;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t index NULL vc1 18 NULL 10000 Using index
drop table t;
#
# MDEV-37435 Assertion `field' failed in virtual bool Item_field::fix_fields(THD *, Item **)
#
CREATE TABLE t1 (a INT,a1 INT AS (a) VIRTUAL,INDEX (a1));
SELECT a FROM t1 GROUP BY a HAVING a>2;
a
SELECT a FROM t1 WHERE a=(SELECT a FROM t1 GROUP BY a HAVING a>2);
a
drop table t1;
create table t1 (a int, a1 int as (a+1) virtual, index(a1));
select a+1 as g from t1 group by g having g>2;
g
drop table t1;
CREATE TABLE t1 (a INT,a1 INT AS (a) VIRTUAL,INDEX (a1));
CREATE TABLE t2 (b INT,b1 INT AS (b) VIRTUAL,INDEX (b1));
insert into t1 (a) select seq from seq_1_to_5;
insert into t2 (b) select seq from seq_1_to_5;
SELECT a, b FROM t1, t2 GROUP BY a, b HAVING a>2and b>2;
a b 33 34 35 43 44 45 53 54 55
drop table t1, t2;
#
# MDEV-37422: SIGSEGV failed in base_list_iterator::replace, Assertion `n < m_size'
# in Baounds_checked_array, ASAN use-after-poison in JOIN::rollup_make_fields
#
CREATE TABLE t1 (
a INT,
b INT,
a1 INT GENERATED ALWAYS AS (a) VIRTUAL,
INDEX (a1)
) ENGINE=INNODB;
SELECT * FROM t1 GROUP BY a WITH ROLLUP;
a b a1
drop table t1;
#
# End of 12.1 tests
#
#
# MDEV-39361 Server crashes in update_depend_map_for_order upon subquery and GROUP BY
#
## original case
CREATE TABLE t1 (i INT, f INT AS (i) VIRTUAL, KEY(f));
INSERT INTO t1 (i) VALUES (1),(2);
SELECT i FROM (SELECT * FROM t1) AS sq GROUP BY i HAVING i > 0;
i 1 2
SELECT i FROM
(SELECT
i,
f,
(select sum(seq) from seq_1_to_10 where seq<t1.f) as DUMMY
FROM t1) AS sq
GROUP BY i HAVING i > 0;
i 1 2
DROP TABLE t1;
## nontrivial vcol expr
CREATE TABLE t1 (i INT, f BIGINT AS (i + 1) VIRTUAL, KEY(f));
INSERT INTO t1 (i) VALUES (1),(2);
SELECT i + 1 as g FROM (SELECT * FROM t1) AS sq GROUP BY g HAVING g > 0;
g 2 3
DROP TABLE t1;
## vcol on vcol
CREATE TABLE t1 (i INT, f BIGINT AS (i + 1) VIRTUAL, g BIGINT as (f), KEY(g));
INSERT INTO t1 (i) VALUES (1),(2);
### no substitution because no index on intermediate vcol
SELECT i + 1 as h FROM (SELECT * FROM t1) AS sq GROUP BY h HAVING h > 0;
h 2 3
SELECT f FROM (SELECT * FROM t1) AS sq GROUP BY f HAVING f > 0;
f 2 3
DROP TABLE t1;
## const vcol (no substitution)
CREATE TABLE t1 (i INT, f INT AS (1 + 1) VIRTUAL, KEY(f));
INSERT INTO t1 (i) VALUES (1),(2);
SELECT 1 + 1 as g FROM (SELECT * FROM t1) AS sq GROUP BY g HAVING g > 0;
g 2
DROP TABLE t1;
# End of 12.3 tests
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-10-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.