--source include/have_rocksdb.inc

#
# Fixed point columns with indexes
#

SET @ORIG_PAUSE_BACKGROUND_WORK = @@ROCKSDB_PAUSE_BACKGROUND_WORK;
SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = 1;

CREATE TABLE t1 (
  d1 DECIMAL(10,2) PRIMARY KEY,
  d2 DECIMAL(60,10),
  n1 NUMERIC,
  n2 NUMERIC(65,4)
) ENGINE=rocksdb;

SHOW INDEX IN t1;

# 5.7 uses strict mode by default, so this will now return an error
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (d1,d2,n1,n2) VALUES 
(10.22,60.12345,123456,14.3456),
(10.0,60.12345,123456,14),
(11.14,15,123456,13),
(100,100,1,2),
(0,0,0,0),
(4540424564.23,3343303441.0,12,13),
(15,17,23,100000);

# now test with the 5.6 behavior just to be sure
set @orig_sql_mode=@@session.sql_mode;
set session sql_mode="";
INSERT INTO t1 (d1,d2,n1,n2) VALUES 
(10.22,60.12345,123456,14.3456),
(10.0,60.12345,123456,14),
(11.14,15,123456,13),
(100,100,1,2),
(0,0,0,0),
(4540424564.23,3343303441.0,12,13),
(15,17,23,100000);
set session sql_mode=@orig_sql_mode;

--replace_column 10 #
EXPLAIN SELECT d1 FROM t1 ORDER BY d1 DESC;
SELECT d1 FROM t1 ORDER BY d1 DESC;

--replace_column 10 #
EXPLAIN SELECT d1 FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY) ORDER BY d1 DESC;
SELECT d1 FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY) ORDER BY d1 DESC;

DROP TABLE t1;

# --error ER_GET_ERRMSG
CREATE TABLE t1 (
  d1 DECIMAL(10,2),
  d2 DECIMAL(60,10),
  n1 NUMERIC,
  n2 NUMERIC(65,4),
  pk NUMERIC PRIMARY KEY,
  UNIQUE INDEX n1_n2 (n1,n2)
) ENGINE=rocksdb;

# --disable_parsing

SHOW INDEX IN t1;

# 5.7 uses strict mode by default, so this will now return an error
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (d1,d2,n1,n2,pk) VALUES
(10.22,60.12345,123456,14.3456,1),
(10.0,60.12345,123456,14,2),
(11.14,15,123456,13,3),
(100,100,1,2,4),
(0,0,0,0,5),
(4540424564.23,3343303441.0,12,13,6),
(15,17,23,100000,7);

# now test with the 5.6 behavior just to be sure
set @orig_sql_mode=@@session.sql_mode;
set session sql_mode="";
INSERT INTO t1 (d1,d2,n1,n2,pk) VALUES
(10.22,60.12345,123456,14.3456,1),
(10.0,60.12345,123456,14,2),
(11.14,15,123456,13,3),
(100,100,1,2,4),
(0,0,0,0,5),
(4540424564.23,3343303441.0,12,13,6),
(15,17,23,100000,7);
set session sql_mode=@orig_sql_mode;


--replace_column 10 #
EXPLAIN SELECT DISTINCT n1+n2 FROM t1;
--sorted_result
SELECT DISTINCT n1+n2 FROM t1;

DROP TABLE t1;

#--enable_parsing

CREATE TABLE t1 (
  d1 DECIMAL(10,2),
  d2 DECIMAL(60,10),
  n1 NUMERIC,
  n2 NUMERIC(65,4),
  pk DECIMAL(20,10) PRIMARY KEY,
  INDEX (d2)
) ENGINE=rocksdb;

SHOW INDEX IN t1;

# 5.7 uses strict mode by default, so this will now return an error
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (d1,d2,n1,n2,pk) VALUES
(10.22,60.12345,123456,14.3456,1),
(10.0,60.12345,123456,14,2),
(11.14,15,123456,13,3),
(100,100,1,2,4),
(0,0,0,0,5),
(4540424564.23,3343303441.0,12,13,6),
(15,17,23,100000,7);

# now test with the 5.6 behavior just to be sure
set @orig_sql_mode=@@session.sql_mode;
set session sql_mode="";
INSERT INTO t1 (d1,d2,n1,n2,pk) VALUES
(10.22,60.12345,123456,14.3456,1),
(10.0,60.12345,123456,14,2),
(11.14,15,123456,13,3),
(100,100,1,2,4),
(0,0,0,0,5),
(4540424564.23,3343303441.0,12,13,6),
(15,17,23,100000,7);
set session sql_mode=@orig_sql_mode;

--replace_column 10 #
EXPLAIN SELECT d2, COUNT(*) FROM t1 GROUP BY d2;
--sorted_result
SELECT d2, COUNT(*) FROM t1 GROUP BY d2;

--replace_column 10 #
EXPLAIN SELECT d2, COUNT(*) FROM t1 IGNORE INDEX FOR GROUP BY (d2) GROUP BY d2;
--sorted_result
SELECT d2, COUNT(*) FROM t1 IGNORE INDEX FOR GROUP BY (d2) GROUP BY d2;

DROP TABLE t1;

SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = @ORIG_PAUSE_BACKGROUND_WORK;
