[MDEV-9341] Update using subquery segfaults Created: 2015-12-29  Updated: 2020-10-18  Resolved: 2020-10-18

Status: Closed
Project: MariaDB Server
Component/s: Triggers
Affects Version/s: 10.1.10
Fix Version/s: 10.1.12

Type: Bug Priority: Major
Reporter: Michiel Hazelhof Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Debian, Jessie, X64


Attachments: Text File log.txt    
Issue Links:
Duplicate
is duplicated by MDEV-9535 Trigger doing "SET NEW.auctionStart =... Closed

 Description   

Query: UPDATE `Sale` SET `Sales_CustomerVAT` = (SELECT `VAT` FROM `Customer` WHERE `Customer_ID` = '10000219') WHERE `Sales_ID` = '14007788'

The database is InnoDB (utf8_general_ci, compact), both columns are varchar(30) utf8_general_ci, not null, reproducable acros multiple servers, log is attached.



 Comments   
Comment by Elena Stepanova [ 2016-01-08 ]

GieltjE,

Please paste the output of

SHOW CREATE TABLE Sale;
SHOW CREATE TABLE Customer;
SHOW INDEX IN Sale;
SHOW INDEX IN Customer;
SHOW GLOBAL VARIABLES;

Also, maybe you could try to run

EXPLAIN UPDATE `Sale` SET `Sales_CustomerVAT` = (SELECT `VAT` FROM `Customer` WHERE `Customer_ID` = '10000219') WHERE `Sales_ID` = '14007788';

Be aware it can also crash, so possibly you won't want to do it if it's production.
If you run it and it does not crash, please paste the output of it as well.

If the data is not strictly confidential, a datadump from these two tables would help a lot (you can upload it to ftp.askmonty.org/private, only MariaDB developers will have access to it).

Thanks.

Comment by Michiel Hazelhof [ 2016-01-11 ]

Explain:

+------+-------------+-------+-------+----------------------------------------+---------+---------+------+------+-----------------------------------------------------+
| id   | select_type | table | type  | possible_keys                          | key     | key_len | ref  | rows | Extra                                               |
+------+-------------+-------+-------+----------------------------------------+---------+---------+------+------+-----------------------------------------------------+
|    1 | PRIMARY     | Sale  | range | PRIMARY,Sales_ID,Sales_ID_2,Sales_ID_3 | PRIMARY | 4       | NULL |    1 | Using where                                         |
|    2 | SUBQUERY    | NULL  | NULL  | NULL                                   | NULL    | NULL    | NULL | NULL | Impossible WHERE noticed after reading const tables |
+------+-------------+-------+-------+----------------------------------------+---------+---------+------+------+-----------------------------------------------------+

SHOW CREATE TABLE Sale;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Sale  | CREATE TABLE `Sale` (
  `Sales_ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Sales_Location` mediumint(8) unsigned NOT NULL,
  `Sales_KioskID` varchar(10) NOT NULL,
  `Terminal_ID` varchar(10) NOT NULL,
  `User_ID` smallint(5) unsigned NOT NULL,
  `Sales_Customer_ID` int(10) unsigned NOT NULL,
  `Sales_Create` datetime NOT NULL,
  `Sales_Complete` datetime DEFAULT NULL,
  `Sales_LastUpdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `Sales_Memo` text NOT NULL,
  `Sales_PackingSlips` smallint(5) unsigned NOT NULL,
  `Sales_Invoices` smallint(5) unsigned NOT NULL,
  `Sales_CustomerOrderID` varchar(50) NOT NULL,
  `Sales_CustomerVAT` varchar(30) DEFAULT NULL,
  `Display_VAT` tinyint(1) NOT NULL,
  `Deleted` tinyint(4) NOT NULL,
  `Status` enum('Offer','Processing','Historic') NOT NULL,
  `PaymentStatus` enum('None','Partial','Full') NOT NULL,
  `Pickup_DT` datetime NOT NULL,
  `Pickup_Location_ID` mediumint(8) unsigned NOT NULL,
  `Pickup_Printed` tinyint(1) NOT NULL,
  `Kiosk_Printed` tinyint(1) NOT NULL,
  `CombineOrder` tinyint(1) NOT NULL,
  `PaymentCondition` enum('8','10','14','21','30','60','Advance') NOT NULL DEFAULT '30',
  `Total` decimal(10,2) NOT NULL,
  `TotalExVAT` decimal(10,2) NOT NULL,
  PRIMARY KEY (`Sales_ID`),
  KEY `Sales_ID` (`Sales_ID`),
  KEY `Sales_ID_2` (`Sales_ID`,`Sales_Location`),
  KEY `Sales_ID_3` (`Sales_ID`,`Sales_Customer_ID`),
  KEY `Sales_Customer_ID` (`Sales_Customer_ID`),
  KEY `Sales_Location` (`Sales_Location`,`Pickup_DT`),
  KEY `Sales_Location_2` (`Sales_Location`,`Terminal_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 
 
SHOW CREATE TABLE Customer;
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Customer | CREATE TABLE `Customer` (
  `Customer_ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `InvoiceDebtor` int(11) unsigned NOT NULL,
  `SaleCombineOrder` tinyint(1) NOT NULL,
  `Gender` enum('','F','M') NOT NULL,
  `First_Name` varchar(100) NOT NULL,
  `Middle_Name` varchar(50) NOT NULL,
  `Sur_Name` varchar(100) NOT NULL,
  `Company` varchar(50) NOT NULL,
  `Phone_Number` varchar(20) NOT NULL,
  `Mobile_Phone_Number` varchar(20) NOT NULL,
  `Fax_Number` varchar(20) NOT NULL,
  `Email` varchar(100) NOT NULL,
  `Website` varchar(100) NOT NULL,
  `Birth_Date` date NOT NULL,
  `Wedding_Date` datetime NOT NULL,
  `Street` varchar(50) NOT NULL,
  `HouseNumber` mediumint(11) unsigned NOT NULL,
  `HouseNumber_Addition` varchar(10) NOT NULL,
  `City` varchar(50) NOT NULL,
  `Postal_Code` varchar(25) NOT NULL,
  `Country` smallint(3) unsigned NOT NULL,
  `EAN` bigint(20) unsigned NOT NULL,
  `BSNRSIN` varchar(30) NOT NULL,
  `KVK` varchar(30) NOT NULL,
  `EstablishmentNumber` varchar(25) NOT NULL,
  `VAT` varchar(30) NOT NULL,
  `Supplier` tinyint(1) NOT NULL,
  `Password` char(64) NOT NULL,
  `Memo` text NOT NULL,
  `Created` datetime NOT NULL,
  `LastModified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `Entry` varchar(15) NOT NULL,
  `PackingSlips` smallint(5) unsigned NOT NULL DEFAULT '1',
  `Invoices` smallint(5) unsigned NOT NULL DEFAULT '1',
  `State` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT '1=not validated per email;2=validated;3=password reset requested',
  `Display_VAT` smallint(1) unsigned NOT NULL,
  `Deleted` tinyint(1) NOT NULL,
  `EDIAdres` varchar(50) NOT NULL,
  `CustomerGroup` enum('Companies','Private','Dispatch') NOT NULL,
  `Image` varchar(100) NOT NULL,
  `PaymentCondition` enum('8','10','14','21','30','60','Advance') NOT NULL DEFAULT '30',
  `Language` char(5) NOT NULL,
  PRIMARY KEY (`Customer_ID`),
  KEY `Customer_ID` (`Customer_ID`),
  KEY `Supplier` (`Supplier`)
) ENGINE=InnoDB AUTO_INCREMENT=10000001 DEFAULT CHARSET=utf8 |
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 
 
SHOW INDEX IN Sale;
+-------+------------+-------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name          | Seq_in_index | Column_name       | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Sale  |          0 | PRIMARY           |            1 | Sales_ID          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_ID          |            1 | Sales_ID          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_ID_2        |            1 | Sales_ID          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_ID_2        |            2 | Sales_Location    | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_ID_3        |            1 | Sales_ID          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_ID_3        |            2 | Sales_Customer_ID | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_Customer_ID |            1 | Sales_Customer_ID | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_Location    |            1 | Sales_Location    | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_Location    |            2 | Pickup_DT         | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_Location_2  |            1 | Sales_Location    | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| Sale  |          1 | Sales_Location_2  |            2 | Terminal_ID       | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+-------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
 
SHOW INDEX IN Customer;
+----------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name    | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Customer |          0 | PRIMARY     |            1 | Customer_ID | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| Customer |          1 | Customer_ID |            1 | Customer_ID | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| Customer |          1 | Supplier    |            1 | Supplier    | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
+----------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

Unfortunately the databases contain direct customer information of our customers which would make it a federal crime to upload them anywhere.

Comment by Elena Stepanova [ 2016-01-12 ]

GieltjE,

Thanks.
According to SHOW INDEX output, your Customer table only has 3 rows, and Sale table is totally empty. Does it sound likely? If not, could you please run CHECK TABLE on both tables, just to rule out that they are broken.

Also, sorry for not mentioning earlier, please attach your cnf file(s).

Comment by Elena Stepanova [ 2016-01-13 ]

GieltjE,

thank you.

Do you have any triggers on the table `Sale` (the one where the crash occurs)? Specifically, BEFORE UPDATE or AFTER UPDATE triggers? If so, could you please also paste their definition and, if they involve any other tables, same SHOW CREATE TABLE and SHOW INDEX for those tables as well?

Comment by Michiel Hazelhof [ 2016-01-15 ]

Yes, a simple one to maintain the lower limit.

BEGIN DECLARE auto_incr BIGINT; SELECT AUTO_INCREMENT INTO auto_incr FROM information_schema.TABLES WHERE table_schema=DATABASE() AND TABLE_NAME='Sale'; IF (auto_incr < 14000001) THEN SET NEW.Sales_ID = 14000001; END IF; END

Comment by Elena Stepanova [ 2016-01-20 ]

GieltjE, thanks.
Was it a one-time crash, or does it happen often? If you can afford risking another crash, can you try to see if it's reproducible?

Do you have a coredump from the crash?

Also, is the trigger above from the same machine where the crash happened, or could it be that it's different there?

Comment by Michiel Hazelhof [ 2016-01-20 ]

The crash is perfectly reproducable and the trigger is from the same machine.

Please advise how to make a core dump.

Comment by Elena Stepanova [ 2016-01-20 ]

To produce a coredump, it should be enough to add core-file option to the server's config file, and maybe also set ulimit -c unlimited.
It should allow to get some core file, but it won't be good, although better than nothing.
If you can start the server and get the crash with a debug binary, it will be much more useful – please let me know and I'll send you the binary.
Thanks.

Comment by Michiel Hazelhof [ 2016-01-24 ]

After running some Debian upgrades it is no longer reproducable, I guess it was some compiler problem.

Comment by Elena Stepanova [ 2016-01-24 ]

Do you happen to remember which version of the compiler you had before upgrades, and could you please paste your build options?
Until now I was assuming you were using MariaDB deb packages, I could try to build the same way you do and see if it changes anything. It would be still good to know for sure, as others might encounter the problem as well.

Comment by Michiel Hazelhof [ 2016-01-24 ]

Start-Date: 2016-01-23 17:56:20
Commandline: apt-get upgrade
Upgrade: libpam-runtime:amd64 (1.1.8-3.1, 1.1.8-3.1+deb8u1), apt:amd64 (1.0.9.8.1, 1.0.9.8.2), multiarch-support:amd64 (2.19-18+deb8u1, 2.19-18+deb8u2), libpam0g:amd64 (1.1.8-3.1, 1.1.8-3.1+deb8u1), apt-utils:amd64 (1.0.9.8.1, 1.0.9.8.2), libc-dev-bin:amd64 (2.19-18+deb8u1, 2.19-18+deb8u2), file:amd64 (5.22+15-2, 5.22+15-2+deb8u1), libmagic1:amd64 (5.22+15-2, 5.22+15-2+deb8u1), libpam-systemd:amd64 (215-17+deb8u2, 215-17+deb8u3), libc-bin:amd64 (2.19-18+deb8u1, 2.19-18+deb8u2), libc6:amd64 (2.19-18+deb8u1, 2.19-18+deb8u2), libapt-inst1.5:amd64 (1.0.9.8.1, 1.0.9.8.2), udev:amd64 (215-17+deb8u2, 215-17+deb8u3), base-files:amd64 (8+deb8u2, 8+deb8u3), libpam-modules:amd64 (1.1.8-3.1, 1.1.8-3.1+deb8u1), libudev1:amd64 (215-17+deb8u2, 215-17+deb8u3), php-mail-mimedecode:amd64 (1.5.5-2, 1.5.5-2+deb8u1), libapt-pkg4.12:amd64 (1.0.9.8.1, 1.0.9.8.2), systemd-sysv:amd64 (215-17+deb8u2, 215-17+deb8u3), php-auth-sasl:amd64 (1.0.6-1, 1.0.6-1+deb8u1), systemd:amd64 (215-17+deb8u2, 215-17+deb8u3), passwd:amd64 (4.2-3, 4.2-3+deb8u1), libpam-modules-bin:amd64 (1.1.8-3.1, 1.1.8-3.1+deb8u1), login:amd64 (4.2-3, 4.2-3+deb8u1), libsystemd0:amd64 (215-17+deb8u2, 215-17+deb8u3), libpcre3:amd64 (8.35-3.3, 8.35-3.3+deb8u2), locales:amd64 (2.19-18+deb8u1, 2.19-18+deb8u2), libc6-dev:amd64 (2.19-18+deb8u1, 2.19-18+deb8u2)
End-Date: 2016-01-23 17:57:32

I am using the prebuild deb packages, compiling it myself is a bit to risky for production environments.

Comment by Elena Stepanova [ 2020-10-18 ]

There was MDEV-9535 filed a bit later, but with a test case. Most likely it was the same problem, as the stack trace is the same. It was fixed in 10.1.12.

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