[MDEV-24387] Wrong number of decimal digits in certain UNION/Subqery constellation Created: 2020-12-10  Updated: 2021-04-05  Resolved: 2021-01-13

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.3.27, 10.4.17, 10.5.8
Fix Version/s: 10.3.28, 10.4.18, 10.5.9

Type: Bug Priority: Major
Reporter: Hartmut Holzgraefe Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-12775 Reuse data type aggregation code for ... Closed

 Description   

UNION of an UNSIGNED result, and a NULL result from a subquery, leads to wrong number of decimals. See the following two one liner test queries, which were run with `mysql --column-type-info`. This only started with 10.3.

MariaDB [test]> select CAST(1 as unsigned) union all select NULL;
Field   1:  `CAST(1 as unsigned)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     2
Max_length: 1
Decimals:   0
Flags:      BINARY NUM 
 
 
+---------------------+
| CAST(1 as unsigned) |
+---------------------+
|                   1 |
|                NULL |
+---------------------+
2 rows in set (0.000 sec)
 
MariaDB [test]> select CAST(1 as unsigned) union all select * from (select NULL) t;
Field   1:  `CAST(1 as unsigned)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     42
Max_length: 40
Decimals:   39
Flags:      BINARY NUM 
 
 
+------------------------------------------+
| CAST(1 as unsigned)                      |
+------------------------------------------+
| 1.00000000000000000000000000000000000000 |
|                                     NULL |
+------------------------------------------+
2 rows in set (0.000 sec)



 Comments   
Comment by Alice Sherepa [ 2020-12-10 ]

it was changed after https://github.com/MariaDB/server/commit/705fc43eaa (MDEV-12775)

Comment by Rucha Deodhar [ 2021-01-12 ]

Patch: https://github.com/MariaDB/server/commit/f2392c72cb354224db36066f62dacb228c70d7a0

Comment by Alexander Barkov [ 2021-01-12 ]

The patch https://github.com/MariaDB/server/commit/f2392c72cb354224db36066f62dacb228c70d7a0 looks OK to me.

I suggest to change tests though:

instead of calling "mysql" command line client, please execute these queries directly in *.test file using --enable_metadata and --disable_metadata around queries.

This is the usual way how we check result set metadata.

Comment by Rucha Deodhar [ 2021-01-12 ]

Patch after latest changes: https://github.com/MariaDB/server/commit/c597d9234c0072a77122f2810212877f1a532d3d

Comment by Alexander Barkov [ 2021-01-13 ]

Ok to push. Thanks!

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