mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
185 lines
5.5 KiB
Text
185 lines
5.5 KiB
Text
--disable_warnings
|
|
drop table if exists t1,t2;
|
|
--enable_warnings
|
|
|
|
|
|
create table t1(str varchar(10) default 'def',strnull varchar(10),intg int default '10',rel double default '3.14');
|
|
|
|
insert into t1 values ('','',0,0.0);
|
|
select default(str), default(strnull), default(intg), default(rel) from t1;
|
|
explain extended select default(str), default(strnull), default(intg), default(rel) from t1;
|
|
select * from t1 where str <> default(str);
|
|
explain select * from t1 where str <> default(str);
|
|
|
|
create view v1 as select default(str), default(strnull), default(intg), default(rel) from t1;
|
|
select * from v1;
|
|
show create view v1;
|
|
drop view v1;
|
|
|
|
#TODO: uncomment when bug will be fixed
|
|
#create table t2 select default(str), default(strnull), default(intg), default(rel) from t1;
|
|
#show create table from t1;
|
|
#insert into t2 select select default(str), default(strnull), default(intg), default(rel) from t1;
|
|
|
|
drop table t1;
|
|
|
|
# End of 4.1 tests
|
|
|
|
#
|
|
# Bug #11314 (HAVING DEFAULT() hangs)
|
|
#
|
|
CREATE TABLE t1 (id int(11), s varchar(20));
|
|
INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three');
|
|
--error 1364
|
|
SELECT s, 32 AS mi FROM t1 GROUP BY s HAVING DEFAULT(mi) IS NULL;
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # Start of 10.2 tests
|
|
--echo #
|
|
|
|
set timestamp=unix_timestamp('2001-01-01 10:20:30.123456');
|
|
create table t1 (a int default 1, b int default (a+1),
|
|
c varchar(100) default 'foo', d text default 'bar',
|
|
e timestamp default now(), f timestamp(6) default now(2));
|
|
insert t1 () values ();
|
|
insert t1 (a) values (10);
|
|
select default(a),default(b),default(c),default(d),default(e),default(f) from t1;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-21639 DEFAULT(col) evaluates to a bad value in WHERE clause
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a BIGINT NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP(),10)));
|
|
INSERT INTO t1 VALUES (10000);
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = 10 AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END=10;
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a DOUBLE NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP(),10)));
|
|
INSERT INTO t1 VALUES (10000);
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = 10 AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END=10;
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a DECIMAL(10,0) NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP(),10)));
|
|
INSERT INTO t1 VALUES (10000);
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = 10 AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END=10;
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a VARCHAR(32) NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP(),10)));
|
|
INSERT INTO t1 VALUES (10000);
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = '10' AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END='10';
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a DATE NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP()%10,DATE'2001-01-01')));
|
|
INSERT INTO t1 VALUES ('2000-01-01');
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = '2001-01-01' AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END='2001-01-01';
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a TIME NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP()%10,TIME'10:20:30')));
|
|
INSERT INTO t1 VALUES ('10:00:00');
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = '10:20:30' AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END='10:20:30';
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a DATETIME NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP(),TIMESTAMP'2001-01-01 10:20:30')));
|
|
INSERT INTO t1 VALUES ('2000-01-01 10:00:00');
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END = '2001-01-01 10:20:30' AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END='2001-01-01 10:20:30';
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a INT NOT NULL DEFAULT (IF(false,UNIX_TIMESTAMP(),FALSE)));
|
|
INSERT INTO t1 VALUES (10);
|
|
SELECT
|
|
a,
|
|
DEFAULT(a),
|
|
CASE WHEN a THEN DEFAULT(a) END AS c,
|
|
CASE WHEN a THEN DEFAULT(a) END IS FALSE AS ce
|
|
FROM t1;
|
|
SELECT a FROM t1 WHERE CASE WHEN a THEN DEFAULT(a) END IS FALSE;
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-21028 Server crashes in Query_arena::set_query_arena upon SELECT from view
|
|
--echo #
|
|
#view protocol generates additional statistics
|
|
--disable_view_protocol
|
|
|
|
create table t1 (a datetime default current_timestamp);
|
|
insert into t1 () values (),();
|
|
create algorithm=temptable view v1 as select * from t1;
|
|
create algorithm=merge view v2 as select * from t1;
|
|
select default(a) = now() from v1;
|
|
select default(a) = now() from v2;
|
|
drop view v1, v2;
|
|
drop table t1;
|
|
|
|
--enable_view_protocol
|
|
|
|
create table t1 (v1 timestamp) select 'x';
|
|
show create table t1;
|
|
select default(v1) from (select v1 from t1) dt;
|
|
select default(v1) from (select v1 from t1 group by v1) dt;
|
|
drop table t1;
|
|
|
|
create table t1 (a text default '');
|
|
create algorithm=temptable view v1 as select * from t1;
|
|
insert into t1 values ('a');
|
|
select default(a) from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-28403 ASAN heap-use-after-free in String::copy / get_field_default_value
|
|
--echo #
|
|
create table t (a blob default 'x');
|
|
create view v as select * from t;
|
|
insert into t () values ();
|
|
update t set a = default;
|
|
query_vertical select table_name,column_name,column_default from information_schema.columns where table_name = 'v';
|
|
drop view v;
|
|
drop table t;
|
|
|
|
--echo #
|
|
--echo # End of 10.2 tests
|
|
--echo #
|