[MDEV-12916] Wrong column data type for an INT field of a cursor-anchored ROW variable Created: 2017-05-25  Updated: 2017-05-27  Resolved: 2017-05-25

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.3
Fix Version/s: 10.3.1

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

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed

 Description   

SET sql_mode=DEFAULT;
DROP PROCEDURE IF EXISTS p1;
DROP TABLE IF EXISTS t1,t2;
DELIMITER $$
CREATE PROCEDURE p1()
BEGIN
  DECLARE a INT DEFAULT 10;
  DECLARE cur1 CURSOR FOR SELECT a;
  BEGIN
    DECLARE rec1 ROW TYPE OF cur1;
    CREATE TABLE t2 AS SELECT rec1.a;
    SHOW CREATE TABLE t2;
    DROP TABLE t2;
  END;
END;
$$
DELIMITER ;
CALL p1();

+-------+-----------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                  |
+-------+-----------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `rec1.a` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------------+

Notice, it created a BIGINT(20) column. Looks wrong. The expected type is INT(11)), as in the declaration of the procedure variable a.

The problem happens at the cursor materialization time, when create_tmp_field_from_item() is called.
It calls Item::create_tmp_field(), which erroneously makes a BIGINT field for Item_splocal with INT data and max_length=11.

The execution path should not go through Item::create_tmp_field() to avoid conversion from INT(11) to BIGINT(11).



 Comments   
Comment by Alexander Barkov [ 2017-05-25 ]

Pushed to bb-10.2-ext.

Reporting 5 hours, as it took around 15 hours for a joint patch fixing 3 bugs:

  • MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
  • MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
  • MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
Generated at Thu Feb 08 08:01:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.