mirror of
				https://github.com/MariaDB/server.git
				synced 2025-10-31 19:06:14 +01:00 
			
		
		
		
	 5a8e6230d7
			
		
	
	
	5a8e6230d7
	
	
	
		
			
			normalize_cond() translated `WHERE col` into `WHERE col<>0`
But the opetator "not equal to 0" does not necessarily exists
for all data types.
For example, the query:
  SELECT * FROM t1 WHERE inet6col;
was translated to:
  SELECT * FROM t1 WHERE inet6col<>0;
which further failed with this error:
  ERROR : Illegal parameter data types inet6 and bigint for operation '<>'
This patch changes the translation from `col<>0` to `col IS TRUE`.
So now
  SELECT * FROM t1 WHERE inet6col;
gets translated to:
  SELECT * FROM t1 WHERE inet6col IS TRUE;
Details:
1. Implementing methods:
   - Field_longstr::val_bool()
   - Field_string::val_bool()
   - Item::val_int_from_val_str()
   If the input contains bad data,
   these methods raise a better error message:
     Truncated incorrect BOOLEAN value
   Before the change, the error was:
     Truncated incorrect DOUBLE value
2. Fixing normalize_cond() to generate Item_func_istrue/Item_func_isfalse
   instances instead of Item_func_ne/Item_func_eq
3. Making Item_func_truth sargable, so it uses the range optimizer.
   Implementing the following methods:
   - get_mm_tree(), get_mm_leaf(), add_key_fields() in Item_func_truth.
   - get_func_mm_tree(), for all Item_func_truth descendants.
4. Implementing the method negated_item() for all Item_func_truth
   descendants, so the negated item has a chance to be sargable:
   For example,
     WHERE NOT col IS NOT FALSE    -- this notation is not sargable
   is now translated to:
     WHERE col IS FALSE            -- this notation is sargable
		
	
			
		
			
				
	
	
		
			87 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| --source include/have_innodb.inc
 | |
| 
 | |
| #
 | |
| # MDEV-8979 IGNORE does not ignore the error 1452
 | |
| #
 | |
| 
 | |
| --echo #
 | |
| --echo # BUG#22037930: INSERT IGNORE FAILS TO IGNORE
 | |
| --echo #               FOREIGN KEY CONSTRAINT
 | |
| 
 | |
| --echo # Setup.
 | |
| CREATE TABLE t1 (fld1 INT PRIMARY KEY) ENGINE=INNODB;
 | |
| CREATE TABLE t2 (fld2 INT, FOREIGN KEY (fld2) REFERENCES t1 (fld1))
 | |
| ENGINE=INNODB;
 | |
| INSERT INTO t1 VALUES(0);
 | |
| INSERT INTO t2 VALUES(0);
 | |
| 
 | |
| --echo # Without fix, an error is reported.
 | |
| INSERT IGNORE INTO t2 VALUES(1);
 | |
| UPDATE IGNORE t2 SET fld2=20 WHERE fld2=0;
 | |
| UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0;
 | |
| 
 | |
| --echo # Test for multi update.
 | |
| UPDATE IGNORE t1, t2 SET t2.fld2= t2.fld2 + 3;
 | |
| UPDATE IGNORE t1, t2 SET t1.fld1= t1.fld1 + 3;
 | |
| 
 | |
| --echo # Reports an error since IGNORE is not used.
 | |
| --error ER_NO_REFERENCED_ROW_2
 | |
| INSERT INTO t2 VALUES(1);
 | |
| 
 | |
| --error ER_NO_REFERENCED_ROW_2
 | |
| UPDATE t2 SET fld2=20 WHERE fld2=0;
 | |
| 
 | |
| --error ER_ROW_IS_REFERENCED_2
 | |
| UPDATE t1 SET fld1=20 WHERE fld1=0;
 | |
| 
 | |
| --error ER_NO_REFERENCED_ROW_2
 | |
| UPDATE t1, t2 SET t2.fld2= t2.fld2 + 3;
 | |
| 
 | |
| --error ER_ROW_IS_REFERENCED_2
 | |
| UPDATE t1, t2 SET t1.fld1= t1.fld1 + 3;
 | |
| 
 | |
| DROP TABLE t2, t1;
 | |
| 
 | |
| --echo #
 | |
| --echo # BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN
 | |
| --echo #               KEY CONSTRAINT
 | |
| 
 | |
| CREATE TABLE t1 (fld1 INT PRIMARY KEY) ENGINE= INNODB;
 | |
| 
 | |
| CREATE TABLE t2 (fld1 VARCHAR(10), fld2 INT NOT NULL,
 | |
| CONSTRAINT fk FOREIGN KEY (fld2) REFERENCES t1(fld1)) ENGINE= INNODB;
 | |
| 
 | |
| --echo # Without patch, reports incorrect error.
 | |
| --error ER_NO_REFERENCED_ROW_2
 | |
| INSERT INTO t2 VALUES('abc', 2) ON DUPLICATE KEY UPDATE fld1= 'def';
 | |
| --error ER_NO_REFERENCED_ROW_2
 | |
| REPLACE INTO t2 VALUES('abc', 2);
 | |
| 
 | |
| --enable_warnings
 | |
| INSERT IGNORE INTO t2 VALUES('abc', 2) ON DUPLICATE KEY UPDATE fld1= 'def';
 | |
| --disable_warnings
 | |
| 
 | |
| DROP TABLE t2, t1;
 | |
| 
 | |
| --echo #
 | |
| --echo # MDEV-26433: assertion: table->get_ref_count() == 0 in dict0dict.cc
 | |
| --echo # line 1915
 | |
| --echo #
 | |
| 
 | |
| --error ER_NO_DEFAULT_FOR_FIELD
 | |
| CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ;
 | |
| 
 | |
| SET @@sql_mode='';
 | |
| --error ER_CONSTRAINT_FAILED
 | |
| CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL DEFAULT '' UNIQUE CHECK (i)) engine=innodb
 | |
|   REPLACE SELECT NULL AS a;
 | |
| 
 | |
| SET @@sql_mode=DEFAULT;
 | |
| --error ER_TRUNCATED_WRONG_VALUE
 | |
| CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL DEFAULT '' UNIQUE CHECK (i)) engine=innodb
 | |
|   REPLACE SELECT NULL AS a;
 | |
| 
 | |
| 
 | |
| --echo #
 | |
| --echo # End of 10.5 tests
 | |
| --echo #
 |