[MDEV-10235] Deadlock in CREATE TABLE ... AS SELECT .. if result set is empty in Galera Created: 2016-06-14  Updated: 2016-06-28  Resolved: 2016-06-15

Status: Closed
Project: MariaDB Server
Component/s: Galera, wsrep
Affects Version/s: 10.1.14
Fix Version/s: 10.1.15

Type: Bug Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Nirbhay Choubey (Inactive)
Resolution: Fixed Votes: 0
Labels: ddl, galera, wsrep


 Description   

If I execute a CREATE TABLE ... AS SELECT ... on a Galera Cluster node, and the result set of the query is empty, then the query will deadlock.

Let's say that we have the following table on a Galera Cluster node:

CREATE TABLE test_tab (
	id integer primary key,
	data varchar(25)
);
 
INSERT INTO test_tab VALUES (4, 'name 33'),
	(7, 'name 33'),
	(13, 'name 33'),
	(16, 'name 33'),
	(19, 'name 33');

The following query works just fine:

MariaDB [db1]> SELECT * FROM test_tab WHERE id=4;
+----+---------+
| id | data    |
+----+---------+
|  4 | name 33 |
+----+---------+
1 row in set (0.00 sec)
 
MariaDB [db1]> CREATE TABLE test_clone1 AS SELECT * FROM test_tab WHERE id=4;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

But this query deadlocks:

MariaDB [db1]> SELECT * FROM test_tab WHERE id=2;
Empty set (0.00 sec)
 
MariaDB [db1]> CREATE TABLE test_clone2 AS SELECT * FROM test_tab WHERE id=2;
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

Galera version:

MariaDB [db1]> show global status like 'wsrep_provider_version';
+------------------------+----------------+
| Variable_name          | Value          |
+------------------------+----------------+
| wsrep_provider_version | 25.3.15(r3578) |
+------------------------+----------------+
1 row in set (0.00 sec)


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