#
# Start of 10.5 tests
#
#
# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB
#
SET default_storage_engine=InnoDB;
#
# Range optimizer
#
CREATE TABLE t1 (a INET6, INDEX(a));
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` inet6 DEFAULT NULL,
  KEY `a` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
FOR i IN 0..255
DO
INSERT INTO t1 VALUES (CONCAT('::', HEX(i)));
END FOR
$$
SELECT * FROM t1 WHERE a='::ff';
a
::ff
EXPLAIN SELECT * FROM t1 WHERE a='::ff';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	a	a	17	const	1	Using where; Using index
SELECT * FROM t1 WHERE a='garbage';
a
Warnings:
Warning	1292	Incorrect inet6 value: 'garbage'
EXPLAIN SELECT * FROM t1 WHERE a='garbage';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
Warnings:
Warning	1292	Incorrect inet6 value: 'garbage'
SELECT * FROM t1 WHERE a>='::fe';
a
::fe
::ff
EXPLAIN SELECT * FROM t1 WHERE a>='::fe';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	a	a	17	NULL	2	Using where; Using index
SELECT * FROM t1 WHERE a>='garbage';
a
EXPLAIN SELECT * FROM t1 WHERE a>='garbage';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0');
a
::80
::a0
::f0
EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	a	a	17	NULL	3	Using where; Using index
SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage');
a
::80
::a0
Warnings:
Warning	1292	Incorrect inet6 value: 'garbage'
EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	a	a	17	NULL	2	Using where; Using index
Warnings:
Warning	1292	Incorrect inet6 value: 'garbage'
SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81';
a
::80
::81
EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	a	a	17	NULL	2	Using where; Using index
SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage';
a
EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6);
a
::ff
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ref	a	a	17	const	1	100.00	Using where; Using index
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = inet6'::ff'
DROP TABLE t1;
#
# MDEV-34922: Assertion `value.length() == FbtImpl::binary_length()' failed in
# Type_handler_fbt<FbtImpl, TypeCollectionImpl>::Field_fbt::store_native,
# Assertion `item->null_value' failed in Type_handler::Item_send_str
#
CREATE TABLE t1 (a datetime);
INSERT INTO t1 VALUES (NULL);
SELECT * FROM (SELECT cast('::' AS INET6),min(1) FROM t1 WHERE if(uuid_short(), a,1)) dt;
cast('::' AS INET6)	min(1)
::	NULL
DROP TABLE t1;
# End of 10.5 tests
#
# MDEV-26742 Assertion `field->type_handler() == this' failed in FixedBinTypeBundle<NATIVE_LEN, MAX_CHAR_LEN>::Type_handler_fbt::stored_field_cmp_to_item
#
CREATE TABLE t1 (pk inet6, c text) engine=myisam;
INSERT INTO t1 VALUES ('::',1);
CREATE TABLE t2 (d text, KEY (d)) engine=innodb ;
Warnings:
Note	1071	Specified key was too long; max key length is 3072 bytes
INSERT INTO t2 VALUES (2);
SELECT * FROM t2 JOIN t1 ON ( t1.pk > t2.d);
d	pk	c
Warnings:
Warning	1292	Incorrect inet6 value: '2'
UPDATE t2 JOIN t1 ON ( t1.pk > t2.d) SET t1.c = 1;
ERROR 22007: Incorrect inet6 value: '2'
SET sql_mode='';
UPDATE t2 JOIN t1 ON ( t1.pk > t2.d) SET t1.c = 1;
Warnings:
Warning	1292	Incorrect inet6 value: '2'
SET sql_mode=DEFAULT;
SELECT * FROM t1;
pk	c
::	1
SELECT * FROM t2;
d
2
DROP TABLE t1, t2;
#
# End of 10.5 tests
#
