[MDEV-23223] If you cancel CTAS Query on MariaDB Server, it will not be canceled and Rollback will be executed Created: 2020-07-20  Updated: 2020-08-18  Resolved: 2020-08-18

Status: Closed
Project: MariaDB Server
Component/s: Server, Storage Engine - InnoDB
Affects Version/s: 10.2.29
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: 이종명 Assignee: Marko Mäkelä
Resolution: Incomplete Votes: 0
Labels: CTAS, Transaction, need_feedback, query, rollback
Environment:

CentOS Linux release 7.6.1810 (Core)
MariaDB 10.2.29


Issue Links:
Relates
relates to MDEV-16515 InnoDB: Failing assertion: ++retries ... Closed
relates to MDEV-21602 CREATE TABLE…PRIMARY KEY…SELECT worka... Closed
relates to MDEV-22456 Dropping the adaptive hash index may ... Closed

 Description   

If you cancel CTAS Query on MariaDB Server, Rollback is executed without cancellation.

For version 10.2.29 the rollback runs very slowly when CTAS Query is cancelled.

For version 10.2.7, the CTAS Query cancellation does not execute Rollback and cancels.

  • Test with version 10.2.7 and version 10.2.29 regarding transaction rollback

    /* View the size of the Transaciton Rollback. */
    SELECT plist.id
         , plist.USER
         , plist.host
         , plist.db
         , plist.command
         , plist.time
         , trx.trx_state
         , trx.trx_started
         , trx.trx_requested_lock_id
         , trx.trx_wait_started
         , trx.trx_weight
         , plist.info
         , trx.trx_query
      FROM information_schema.processlist       AS plist
      LEFT JOIN information_schema.innodb_trx   AS trx  ON plist.id = trx.trx_mysql_thread_id
     WHERE plist.USER = 'jmlee'
       AND trx.trx_weight IS NOT NULL;
     
    /* Test for INSERT Query */
    START TRANSACTION;
    INSERT INTO temp_jmlee_order
    SELECT *
      FROM table_order
     WHERE order_dt < '2017-01-01';
    ROLLBACK;
    Results)
    Version 10.2.29 / ROWS : 407,082 / INSERT : 17.52s / ROLLBACK : 21.58s
    Version 10.2.07 / ROWS : 407,082 / INSERT : 20.87s / ROLLBACK : 22.12s
     
    /* Test for UPDATE Query */
    START TRANSACTION;
    UPDATE temp_jmlee_order         AS too
      JOIN table_order              AS o    ON too.order_seq = o.order_seq
      JOIN table_order_item         AS oi   ON o.order_seq = oi.order_seq
      JOIN table_order_item_box     AS oid  ON oi.order_item_seq = oid.order_item_seq
                                           AND too.order_item_seq = oid.order_item_seq
                                           AND too.box_seq = oid.box_seq
       SET too.device_type_cd = o.device_type_cd
         , too.inbd_date = concat(LEFT(oid.inbd_date, 7), '-01')
     WHERE 1=1;
    ROLLBACK;
    Results)
    Version 10.2.29 / ROWS : 350,723 / UPDATE : 12.36s / ROLLBACK : 08.39s
    Version 10.2.07 / ROWS : 350,723 / UPDATE : 24.99s / ROLLBACK : 08.18s
     
    /* Test for DELETE Query */
    START TRANSACTION;
    DELETE
      FROM temp_jmlee_order
     WHERE 1=1;
    ROLLBACK;
    Results)
    Version 10.2.29 / ROWS : 407,082 / UPDATE : 10.76s / ROLLBACK : 06.85s
    Version 10.2.07 / ROWS : 407,082 / UPDATE : 20.09s / ROLLBACK : 06.56s
     
    /* Test for CTAS Query */
    SET @END_DT = CAST('2017-01-01' AS DATE);
    START TRANSACTION;
    INSERT INTO temp_jmlee_order
    SELECT o.order_seq
         , oi.order_item_seq
         , oid.box_seq
         , ifnull(sum(floor(CAST(( IF(p.proc_yn = 'Y', 1, ifnull(CAST(oid.fix_kg AS DECIMAL(10,2)), 0))
                                 * IF(p.proc_yn = 'N' AND p.large_purchase_gbn = 'Y', 1, ifnull(oid.box_cnt, 0))
                                 * ( ifnull(IF(oi.group_purchase_gbn = 'N', oi.price_per_kg, ifnull(oi.purchase_price_per_kg, oi.price_per_kg)), 0)
                                   + ifnull(oi.opt1_price, 0) + ifnull(oi.opt2_price, 0) + ifnull(oi.opt3_price, 0) + ifnull(oi.opt4_price, 0))
                                 )
                                 + (ifnull(oid.dist_price + oid.dist_over_region_price, 0) * IF(p.large_purchase_gbn = 'Y', 1, ifnull(oid.box_cnt, 0)))
                                 + 0.5 AS DECIMAL(15,2)))), 0) AS charge_price
      FROM table_order
      JOIN table_order_item         AS oi   ON o.order_seq = oi.order_seq
      JOIN table_order_item_box     AS oid  ON oi.order_item_seq = oid.order_item_seq
      JOIN table_item               AS i    ON oi.item_seq = i.item_seq
      JOIN table_product            AS p    ON i.product_seq = p.product_seq
     WHERE o.order_dt < @END_DT
     GROUP BY o.order_seq
         , oi.order_item_seq
         , oid.box_seq;
    ROLLBACK;
    Results)
    Version 10.2.29 / ROWS : 359,271 / INSERT : 47.81s / ROLLBACK : 02.44s
    Version 10.2.07 / ROWS : 359,271 / INSERT : 46.33s / ROLLBACK : 02.43s
     
    SET @END_DT = CAST('2017-01-01' AS DATE);
    CREATE OR REPLACE TABLE temp_jmlee_order
    AS 
    SELECT o.order_seq
         , oi.order_item_seq
         , oid.box_seq
         , ifnull(sum(floor(CAST(( IF(p.proc_yn = 'Y', 1, ifnull(CAST(oid.fix_kg AS DECIMAL(10,2)), 0))
                                 * IF(p.proc_yn = 'N' AND p.large_purchase_gbn = 'Y', 1, ifnull(oid.box_cnt, 0))
                                 * ( ifnull(IF(oi.group_purchase_gbn = 'N', oi.price_per_kg, ifnull(oi.purchase_price_per_kg, oi.price_per_kg)), 0)
                                   + ifnull(oi.opt1_price, 0) + ifnull(oi.opt2_price, 0) + ifnull(oi.opt3_price, 0) + ifnull(oi.opt4_price, 0))
                                 )
                                 + (ifnull(oid.dist_price + oid.dist_over_region_price, 0) * IF(p.large_purchase_gbn = 'Y', 1, ifnull(oid.box_cnt, 0)))
                                 + 0.5 AS DECIMAL(15,2)))), 0) AS charge_price
      FROM table_order
      JOIN table_order_item         AS oi   ON o.order_seq = oi.order_seq
      JOIN table_order_item_box     AS oid  ON oi.order_item_seq = oid.order_item_seq
      JOIN table_item               AS i    ON oi.item_seq = i.item_seq
      JOIN table_product            AS p    ON i.product_seq = p.product_seq
     WHERE o.order_dt < @END_DT
     GROUP BY o.order_seq
         , oi.order_item_seq
         , oid.box_seq;
    Results)
    Version 10.2.29 / ROWS : 359,271 / Run Rollback on Query Cancellation
    Version 10.2.07 / ROWS : 359,271 / Rollback not executed on query cancellation
    

  • Test result : There is a problem with rollback when canceling CTAS query at 10.2.29.


 Comments   
Comment by Marko Mäkelä [ 2020-07-20 ]

jmlee, what exactly do you mean by not executing rollback? CREATE TABLE…SELECT is internally implemented as two separate transactions, corresponding to CREATE TABLE and INSERT…SELECT. If an error occurs during the latter part (for example, a duplicate key is being inserted), then the equivalent of DROP TABLE will be executed (as noted in MDEV-21602).

MDEV-16515 in MariaDB 10.1.35, 10.2.17, 10.3.8 introduced a check whether DROP TABLE is being interrupted. That check was disabled in MDEV-22456, which was released in 10.5.4 and will be part of the upcoming 10.2.33, 10.3.24, 10.4.14 releases.

If you mean that the table created by CREATE TABLE…SELECT remains after the interrupt, I suspect that the problem was introduced by MDEV-16515 and removed by MDEV-22456.

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