Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-1431

DELETE using Subqueries

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 4.2.0
    • 4.3.0, 3.3.0, 3.2.2, 4.2.2
    • None
    • None
    • hdfs 2.5.0
      hbase-0.98.7
      phoenix 4.2.0

    Description

      DELETE's using a subquery deletes all the rows in the table igonoring any condition set by the where clause, here's an example -

      CREATE TABLE IF NOT EXISTS CUSTOMER (
      CUSTOMER_ID INTEGER NOT NULL,
      CUSTOMER_NAME VARCHAR NOT NULL,
      CUSTOMER_CITY VARCHAR
      CONSTRAINT pk PRIMARY KEY (CUSTOMER_ID,CUSTOMER_NAME)
      );

      CREATE TABLE IF NOT EXISTS SALES (
      SALE_ID INTEGER NOT NULL,
      CUSTOMER_NAME VARCHAR NOT NULL,
      SALE_AMOUNT INTEGER
      CONSTRAINT pk PRIMARY KEY (SALE_ID,CUSTOMER_NAME)
      );

      UPSERT INTO CUSTOMER VALUES(1,'MSFT','SEATTLE');
      UPSERT INTO CUSTOMER VALUES(2,'AMZN','SEATTLE');
      UPSERT INTO CUSTOMER VALUES(3,'APPL','CUPERTINO');
      UPSERT INTO CUSTOMER VALUES(4,'TSLA','PALO ALTO');

      UPSERT INTO SALES VALUES(1,'MSFT',1000);
      UPSERT INTO SALES VALUES(2,'AMZN',1000);
      UPSERT INTO SALES VALUES(3,'APPL',1000);
      UPSERT INTO SALES VALUES(4,'TSLA',1000);

      DELETE FROM SALES WHERE CUSTOMER_NAME IN (SELECT CUSTOMER_NAME FROM CUSTOMER WHERE CUSTOMER_CITY = 'SEATTLE' ) => Deletes all the rows

      EXPLAIN DELETE FROM SALES WHERE CUSTOMER_NAME IN (SELECT CUSTOMER_NAME FROM CUSTOMER WHERE CUSTOMER_CITY = 'SEATTLE' )
      ------------

      PLAN

      ------------

      DELETE ROWS
      CLIENT PARALLEL 1-WAY FULL SCAN OVER SALES
      SERVER FILTER BY FIRST KEY ONLY

      EXPLAIN DELETE FROM SALES;
      ------------

      PLAN

      ------------

      DELETE ROWS
      CLIENT PARALLEL 1-WAY FULL SCAN OVER SALES
      SERVER FILTER BY FIRST KEY ONLY

      Attachments

        1. 1431.patch
          4 kB
          Wei Xue

        Activity

          People

            maryannxue Wei Xue
            fthomas Frédéric Thomas
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: