[MDEV-16534] PPC64: Unexpected error with a negative value into auto-increment columns in HEAP, MyISAM, ARIA Created: 2018-06-20  Updated: 2018-07-03  Resolved: 2018-06-20

Status: Closed
Project: MariaDB Server
Component/s: Platform Power, Storage Engine - Aria, Storage Engine - Memory, Storage Engine - MyISAM
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 5.5.61, 10.0.36, 10.1.35, 10.2.16, 10.3.8, 10.4.0

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

Issue Links:
Relates
relates to MDEV-15352 AUTO_INCREMENT breaks after updating ... Closed
relates to MDEV-16652 heap.heap_auto_increment, main.auto_i... Closed

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
  id TINYINT NOT NULL AUTO_INCREMENT,
  name CHAR(30) NOT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB;
INSERT INTO t1 (name) VALUES ('dog');
UPDATE t1 SET id=-1 WHERE id=1;
INSERT INTO t1 (name) VALUES ('cat');
SELECT * FROM t1;
DROP TABLE t1;

+----+------+
| id | name |
+----+------+
| -1 | dog  |
|  2 | cat  |
+----+------+

If I now change ENGINE to HEAP, MyISAM or ARIA:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
  id TINYINT NOT NULL AUTO_INCREMENT,
  name CHAR(30) NOT NULL,
  PRIMARY KEY (id)
) ENGINE=MyISAM;
INSERT INTO t1 (name) VALUES ('dog');
UPDATE t1 SET id=-1 WHERE id=1;
INSERT INTO t1 (name) VALUES ('cat');
SELECT * FROM t1;
DROP TABLE t1;

the script fails in the last INSERT with this error:

ERROR 167 (22003): Out of range value for column 'id' at row 1

Looks wrong. All engines should insert two rows without errors, like InnoDB does.

Note, if I run the same scripts on other platforms (e.g. x86-64), all engines work as expected, like InnoDB.

The problem resides in these code fragments in HEAP, MyISAM and ARIA implementations respectively:

void heap_update_auto_increment(HP_INFO *info, const uchar *record)
{
..
  case HA_KEYTYPE_INT8:
    s_value= (longlong) *(char*)key;
    break;
..
}

ulonglong retrieve_auto_increment(MI_INFO *info,const uchar *record)
{
..
  case HA_KEYTYPE_INT8:
    s_value= (longlong) *(char*)key;
    break;
..
}

ulonglong ma_retrieve_auto_increment(const uchar *key, uint8 key_type)
{
..
  case HA_KEYTYPE_INT8:
    s_value= (longlong) *(const char*)key;
    break;
 
..
}

"char" is unsigned by default on PPC64.
The cast operators should include the "signed" keyword, i.e:

  case HA_KEYTYPE_INT8:
    s_value= (longlong) *(const signed char*)key;
    break;


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