[MDEV-13863] sql_mode=ORACLE: DECODE does not treat two NULLs as equivalent Created: 2017-09-22  Updated: 2020-08-25  Resolved: 2017-09-23

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.3
Fix Version/s: 10.3.2

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: Compatibility

Issue Links:
Blocks
is blocked by MDEV-13864 Change Item_func_case to store the pr... Closed
Relates
relates to MDEV-10342 Providing compatibility for basic SQL... Closed

 Description   

This script returns 2:

SET sql_mode=ORACLE;
SELECT DECODE(NULL,NULL,1,2) AS a FROM DUAL;

+------+
| a    |
+------+
|    2 |
+------+

DECODE is internally implemented using Item_func_case, which treats two NULL values as not equal, so therefore the default value 2 is returned.

Oracle database works differently:

In a DECODE function, Oracle considers two nulls to be equivalent. If expr is null, then Oracle returns the result of the first search that is also null.

The above query returns 1 in Oracle:

SELECT DECODE(NULL,NULL,1,2) AS a FROM DUAL;

	 A
----------
	 1

This script demonstrates the same problem, now using a table column instead of an explicit NULL literal:

SET sql_mode=ORACLE;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10));
INSERT INTO t1 VALUES (NULL);
SELECT a, DECODE(a,NULL,1,2) AS da FROM t1;

MariaDB returns:

+------+------+
| a    | da   |
+------+------+
| NULL |    2 |
+------+------+

Oracle database returns:

A		   DA
---------- ----------
		    1

DECODE should be fixed to treat two NULL values as equivalent.



 Comments   
Comment by Alexander Barkov [ 2017-09-23 ]

Pushed to bb-10.2-ext and 10.3

Generated at Thu Feb 08 08:08:57 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.