mariadb/mysql-test/suite/vcol/t/vcol_misc.test

327 lines
8.1 KiB
Text
Raw Normal View History

--source include/have_ucs2.inc
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
#
# Bug#601164: DELETE/UPDATE with ORDER BY index and LIMIT
#
create table t1 (a int, b int, v int as (a+1), index idx(b));
insert into t1(a, b) values
(4, 40), (3, 30), (5, 50), (7, 70), (8, 80), (2, 20), (1, 10);
select * from t1 order by b;
delete from t1 where v > 6 order by b limit 1;
select * from t1 order by b;
update t1 set a=v order by b limit 1;
select * from t1 order by b;
drop table t1;
#
# Bug#604549: Expression for virtual column returns row
#
MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard MDEV-10134 Add full support for DEFAULT - Added support for using tables with MySQL 5.7 virtual fields, including MySQL 5.7 syntax - Better error messages also for old cases - CREATE ... SELECT now also updates timestamp columns - Blob can now have default values - Added new system variable "check_constraint_checks", to turn of CHECK constraint checking if needed. - Removed some engine independent tests in suite vcol to only test myisam - Moved some tests from 'include' to 't'. Should some day be done for all tests. - FRM version increased to 11 if one uses virtual fields or constraints - Changed to use a bitmap to check if a field has got a value, instead of setting HAS_EXPLICIT_VALUE bit in field flags - Expressions can now be up to 65K in total - Ensure we are not refering to uninitialized fields when handling virtual fields or defaults - Changed check_vcol_func_processor() to return a bitmap of used types - Had to change some functions that calculated cached value in fix_fields to do this in val() or getdate() instead. - store_now_in_TIME() now takes a THD argument - fill_record() now updates default values - Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL - Automatically generate a name for constraints that doesn't have a name - Added support for ALTER TABLE DROP CONSTRAINT - Ensure that partition functions register virtual fields used. This fixes some bugs when using virtual fields in a partitioning function
2016-06-29 09:14:22 +02:00
-- error ER_OPERAND_COLUMNS
CREATE TABLE t1 (
a int NOT NULL DEFAULT '0',
v double AS ((1, a)) VIRTUAL
);
#
# Bug#603654: Virtual column in ORDER BY, no other references of table columns
#
CREATE TABLE t1 (
a CHAR(255) BINARY NOT NULL DEFAULT 0,
b CHAR(255) BINARY NOT NULL DEFAULT 0,
v CHAR(255) BINARY AS (CONCAT(a,b)) VIRTUAL );
INSERT INTO t1(a,b) VALUES ('4','7'), ('4','6');
SELECT 1 AS C FROM t1 ORDER BY v;
DROP TABLE t1;
#
2010-07-17 21:58:08 +02:00
# Bug#603186: Insert into a table with stored vurtual columns
#
CREATE TABLE t1(a int, b int DEFAULT 0, v INT AS (b+10) PERSISTENT);
INSERT INTO t1(a) VALUES (1);
SELECT b, v FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a int DEFAULT 100, v int AS (a+1) PERSISTENT);
INSERT INTO t1 () VALUES ();
CREATE TABLE t2(a int DEFAULT 100 , v int AS (a+1));
INSERT INTO t2 () VALUES ();
SELECT a, v FROM t1;
SELECT a, v FROM t2;
DROP TABLE t1,t2;
2010-07-17 21:58:08 +02:00
#
# Bug#604503: Virtual column expression with datetime comparison
#
CREATE TABLE t1 (
a datetime NOT NULL DEFAULT '2000-01-01',
v boolean AS (a < '2001-01-01')
);
INSERT INTO t1(a) VALUES ('2002-02-15');
INSERT INTO t1(a) VALUES ('2000-10-15');
SELECT a, v FROM t1;
SELECT a, v FROM t1;
CREATE TABLE t2 (
a datetime NOT NULL DEFAULT '2000-01-01',
v boolean AS (a < '2001-01-01') PERSISTENT
);
INSERT INTO t2(a) VALUES ('2002-02-15');
INSERT INTO t2(a) VALUES ('2000-10-15');
SELECT * FROM t2;
DROP TABLE t1, t2;
#
# Bug#607566: Virtual column in the select list of SELECT with ORDER BY
#
CREATE TABLE t1 (
a char(255), b char(255), c char(255), d char(255),
v char(255) AS (CONCAT(c,d) ) VIRTUAL
);
INSERT INTO t1(a,b,c,d) VALUES ('w','x','y','z'), ('W','X','Y','Z');
SELECT v FROM t1 ORDER BY CONCAT(a,b);
DROP TABLE t1;
2010-07-21 20:10:12 +02:00
#
# Bug#607168: CREATE TABLE AS SELECT that returns virtual columns
#
CREATE TABLE t1 (f1 INTEGER, v1 INTEGER AS (f1) VIRTUAL);
CREATE TABLE t2 AS SELECT v1 FROM t1;
SHOW CREATE TABLE t2;
DROP TABLE t1,t2;
2010-07-27 00:00:56 +02:00
#
# Bug#607177: ROUND function in the expression for a virtual function
#
CREATE TABLE t1 (p int, a double NOT NULL, v double AS (ROUND(a,p)) VIRTUAL);
INSERT INTO t1 VALUES (0,1,0);
INSERT INTO t1 VALUES (NULL,0,0);
SELECT a, p, v, ROUND(a,p), ROUND(a,p+NULL) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (p int, a double NOT NULL);
INSERT INTO t1(p,a) VALUES (0,1);
INSERT INTO t1(p,a) VALUES (NULL,0);
SELECT a, p, ROUND(a,p), ROUND(a,p+NULL) FROM t1;
DROP TABLE t1;
#
# Bug#610890: SHOW CREATE TABLE with a virtual column
#
CREATE TABLE t1 (a char(32), v char(32) CHARACTER SET ucs2 AS (a) VIRTUAL);
SHOW CREATE TABLE t1;
DROP TABLE t1;
#
# Bug#930814: no info in information schema for tables with virtual columns
#
CREATE TABLE t1 (a int, b int);
CREATE TABLE t2 (a int, b int as (a+1) VIRTUAL);
SELECT table_schema, table_name, column_name, column_type, extra
FROM information_schema.columns WHERE table_name = 't1';
SELECT table_schema, table_name, column_name, column_type, extra
FROM information_schema.columns WHERE table_name = 't2';
DROP TABLE t1,t2;
2012-03-14 12:58:18 +01:00
#
# Bug mdev-354: virtual columns of ENUM and SET types
#
create table t1 (
a int not null, b char(2) not null,
c enum('Y','N') as (case when b = 'aa' then 'Y' else 'N' end) persistent
);
show create table t1;
insert into t1(a,b) values (1,'bb'), (2,'aa'), (3,'cc');
select * from t1;
create table t2 (
a int, b int,
c set("y","n")
as (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) persistent
);
show create table t2;
insert into t2(a,b) values (7,0), (2,3), (0,1);
select * from t2;
drop table t1,t2;
2012-06-24 00:00:05 +02:00
#
# Bug mdev-3938: INSERT DELAYED for a table with virtual columns
#
CREATE TABLE t1 (
ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
tsv TIMESTAMP AS (ADDDATE(ts, INTERVAL 1 DAY)) VIRTUAL
) ENGINE=MyISAM;
INSERT INTO t1 (tsv) VALUES (DEFAULT);
INSERT DELAYED INTO t1 (tsv) VALUES (DEFAULT);
FLUSH TABLES;
SELECT COUNT(*) FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-4823 Server crashes in Item_func_not::fix_fields on
--echo # creating a table with a virtual column using NOT
--echo #
CREATE TABLE t1 ( f1 INT, v4 INT AS ( NOT f1 ) VIRTUAL );
drop table t1;
--echo # end of 5.2 tests
2013-08-15 23:04:20 +02:00
#
# SELECT that uses a virtual column and executed with BKA
#
create table t1 (a int, b int);
insert into t1 values (3, 30), (4, 20), (1, 20);
create table t2 (c int, d int, v int as (d+1), index idx(c));
insert into t2(c,d) values
(20, 100), (20, 300), (30, 100), (30, 200), (40, 500),
(70, 100), (40, 300), (60, 100), (40, 100), (70, 100);
insert into t2(c,d) values
(120, 100), (150, 300), (130, 100), (130, 200), (140, 500),
(170, 100), (180, 300), (160, 100), (40, 100), (170, 100);
set join_cache_level=6;
explain
select * from t1,t2 where t1.b=t2.c and d <= 100;
select * from t1,t2 where t1.b=t2.c and d <= 100;
set join_cache_level=default;
drop table t1, t2;
Merge with 5.1-microseconds A lot of small fixes and new test cases. client/mysqlbinlog.cc: Cast removed client/mysqltest.cc: Added missing DBUG_RETURN include/my_pthread.h: set_timespec_time_nsec() now only takes one argument mysql-test/t/date_formats.test: Remove --disable_ps_protocl as now also ps supports microseconds mysys/my_uuid.c: Changed to use my_interval_timer() instead of my_getsystime() mysys/waiting_threads.c: Changed to use my_hrtime() sql/field.h: Added bool special_const_compare() for fields that may convert values before compare (like year) sql/field_conv.cc: Added test to get optimal copying of identical temporal values. sql/item.cc: Return that item_int is equal if it's positive, even if unsigned flag is different. Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions Added proper NULL check to Item_cache_int::save_in_field() sql/item_cmpfunc.cc: Don't call convert_constant_item() if there is nothing that is worth converting. Simplified test when years should be converted sql/item_sum.cc: Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime() sql/item_timefunc.cc: Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds. Added Item_temporal_func::get_time() (This simplifies some things) sql/mysql_priv.h: Added Lazy_string_decimal() sql/mysqld.cc: Added my_decimal constants max_seconds_for_time_type, time_second_part_factor sql/table.cc: Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields() sql/tztime.cc: TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors This is needed to be able to detect if timestamp is 0 storage/maria/lockman.c: Changed from my_getsystime() to set_timespec_time_nsec() storage/maria/ma_loghandler.c: Changed from my_getsystime() to my_hrtime() storage/maria/ma_recovery.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/maria/unittest/trnman-t.c: Changed from my_getsystime() to mmicrosecond_interval_timer() storage/xtradb/handler/ha_innodb.cc: Added support for new time,datetime and timestamp unittest/mysys/thr_template.c: my_getsystime() -> my_interval_timer() unittest/mysys/waiting_threads-t.c: my_getsystime() -> my_interval_timer()
2011-05-28 04:11:32 +02:00
#
# Test crashes when using convert_const_item()
#
create table t1 (a bigint, b bigint as (a > '2'));
show create table t1;
insert into t1 (a) values (1),(3);
select * from t1;
select * from t1;
drop table t1;
create table t1 (a bigint, b bigint as (a between 0 and 2));
show create table t1;
insert into t1 (a) values (1),(3);
select * from t1;
select * from t1;
drop table t1;
create table t1 (a char(10), b char(10) as (a between 0 and 2));
show create table t1;
insert into t1 (a) values (1),(3);
select * from t1;
select * from t1;
drop table t1;
#
# Test output of show columns
#
CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` varchar(32) DEFAULT NULL,
`c` int(11) AS (a MOD 10) VIRTUAL,
`d` varchar(5) AS (LEFT(b,5)) PERSISTENT
) ENGINE=MyISAM;
show create table t1;
show columns from t1;
2011-06-10 15:42:55 +02:00
--replace_column 8 #
show full columns from t1;
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,NULL);
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
set sql_mode='strict_all_tables';
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
drop table t1;
2013-08-15 23:04:20 +02:00
--echo #
--echo # MDEV-5611: self-referencing virtual column
--echo #
MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard MDEV-10134 Add full support for DEFAULT - Added support for using tables with MySQL 5.7 virtual fields, including MySQL 5.7 syntax - Better error messages also for old cases - CREATE ... SELECT now also updates timestamp columns - Blob can now have default values - Added new system variable "check_constraint_checks", to turn of CHECK constraint checking if needed. - Removed some engine independent tests in suite vcol to only test myisam - Moved some tests from 'include' to 't'. Should some day be done for all tests. - FRM version increased to 11 if one uses virtual fields or constraints - Changed to use a bitmap to check if a field has got a value, instead of setting HAS_EXPLICIT_VALUE bit in field flags - Expressions can now be up to 65K in total - Ensure we are not refering to uninitialized fields when handling virtual fields or defaults - Changed check_vcol_func_processor() to return a bitmap of used types - Had to change some functions that calculated cached value in fix_fields to do this in val() or getdate() instead. - store_now_in_TIME() now takes a THD argument - fill_record() now updates default values - Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL - Automatically generate a name for constraints that doesn't have a name - Added support for ALTER TABLE DROP CONSTRAINT - Ensure that partition functions register virtual fields used. This fixes some bugs when using virtual fields in a partitioning function
2016-06-29 09:14:22 +02:00
--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
create table t1 (a int, b int as (b is null) virtual);
MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard MDEV-10134 Add full support for DEFAULT - Added support for using tables with MySQL 5.7 virtual fields, including MySQL 5.7 syntax - Better error messages also for old cases - CREATE ... SELECT now also updates timestamp columns - Blob can now have default values - Added new system variable "check_constraint_checks", to turn of CHECK constraint checking if needed. - Removed some engine independent tests in suite vcol to only test myisam - Moved some tests from 'include' to 't'. Should some day be done for all tests. - FRM version increased to 11 if one uses virtual fields or constraints - Changed to use a bitmap to check if a field has got a value, instead of setting HAS_EXPLICIT_VALUE bit in field flags - Expressions can now be up to 65K in total - Ensure we are not refering to uninitialized fields when handling virtual fields or defaults - Changed check_vcol_func_processor() to return a bitmap of used types - Had to change some functions that calculated cached value in fix_fields to do this in val() or getdate() instead. - store_now_in_TIME() now takes a THD argument - fill_record() now updates default values - Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL - Automatically generate a name for constraints that doesn't have a name - Added support for ALTER TABLE DROP CONSTRAINT - Ensure that partition functions register virtual fields used. This fixes some bugs when using virtual fields in a partitioning function
2016-06-29 09:14:22 +02:00
create table t1 (a int as (1+1), b int as (a is null) virtual);
drop table t1;
2013-08-15 23:04:20 +02:00
--echo # end of 5.3 tests
#
# MDEV-7655 SHOW CREATE TABLE returns invalid DDL when using virtual columns along with a table collation
#
create table t1 (v1 varchar(255) as (c1) persistent, c1 varchar(50)) collate=latin1_general_ci;
show create table t1;
drop table t1;
2015-12-21 21:24:22 +01:00
--echo #
--echo # Start of 10.1 tests
--echo #
--echo #
--echo # MDEV-8441 Bad SHOW CREATE TABLE output for a table with a virtual column
--echo #
CREATE TABLE t1 (a DATETIME, b TIMESTAMP AS (TIMESTAMP(a)));
SHOW CREATE TABLE t1;
DROP TABLE t1;
# Make sure that if the first TIMESTAMP column appears to be virtual,
# then no further promotion is done, so the next TIMESTAMP column "c" does not
# get the "DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" attributes.
CREATE TABLE t1 (a DATETIME, b TIMESTAMP AS (TIMESTAMP(a)),c TIMESTAMP);
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo #
--echo # MDEV-8839 COLUMN_GET() produces warnings with no data
--echo #
SET @aaa= COLUMN_CREATE('price', _binary 0xF0F1F2F3F4F5F6F7);
SELECT COLUMN_GET(@aaa, 'price' AS DECIMAL) aaa;
SELECT COLUMN_GET(@aaa, 'price' AS INT) aaa;
SELECT COLUMN_GET(@aaa, 'price' AS DOUBLE) aaa;
--echo #
--echo # End of 10.1 tests
--echo #