[MDEV-14933] Wrong result caused by UNSIGNED column and UNION ALL Created: 2018-01-12  Updated: 2018-01-16  Resolved: 2018-01-16

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 5.5, 10.0, 10.1, 10.2.12, 10.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Pavel Cibulka Assignee: Alexander Barkov
Resolution: Duplicate Votes: 0
Labels: upstream

Issue Links:
Duplicate
duplicates MDEV-9495 Wrong field type for a UNION of a sig... Closed

 Description   

SELECT returns wrong data when UNION ALL is used and first table has unsigned column and second table has signed data in this column.

Example:

CREATE TABLE `pokus` (
  `id` INT NOT NULL,
  `unsigned_column` SMALLINT UNSIGNED NOT NULL,
  PRIMARY KEY (`id`));
 
INSERT INTO `pokus` (`id`, `unsigned_column`) VALUES ('1', '5');
 
SELECT id, unsigned_column FROM pokus
UNION ALL
SELECT id, -unsigned_column FROM pokus;

result:

'1', '5'
'1', '0'

Second row has 0 in second column, it should have -5.



 Comments   
Comment by Alice Sherepa [ 2018-01-15 ]

Thanks for the report!
Reproducible on MariaDB 5.5-10.2, mysql 5.7.19
Fixed in MariaDB 10.3.1, commit 705fc43eaafccd7a41e5 by Alexander Barkov.

	CREATE TABLE `t1` (`u` INT UNSIGNED);
	INSERT INTO `t1` VALUES ('5');
	SELECT u FROM t1 UNION  SELECT -u FROM t1;
	DROP TABLE t1;

Comment by Alexander Barkov [ 2018-01-16 ]

Fixing in versions prior to 10.3 is not possible.
Please use a CAST(..AS DECIMAL(M,N)) as a workaround.

This was fixed in 10.3 in a commit for MDEV-12775, which was a huge and intrusive patch and we cannot realistically backport it into a GA release.
See "git show 705fc43eaafccd7a41e541f3149a917850f4e2fb" in the 10.3 branch.

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