Skip to content

Instantly share code, notes, and snippets.

@parhamr
Last active December 25, 2015 17:18
Show Gist options
  • Save parhamr/7011685 to your computer and use it in GitHub Desktop.
Save parhamr/7011685 to your computer and use it in GitHub Desktop.

Revisions

  1. parhamr renamed this gist Oct 17, 2013. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions SQLexample.md → Magento1.12-SQL_type_example.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,11 @@ possible_keys: NULL
    rows: 773625
    Extra: Using where
    1 row in set (0.00 sec)
    ```

    This query is much faster:

    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN(433284, 433283)\G;
    *************************** 1. row ***************************
    id: 1
    @@ -30,3 +34,20 @@ possible_keys: PRIMARY,IDX_CATALOGPRODUCTINDEXPRICE_ENTITYID
    1 row in set (0.00 sec)
    ```

    Incorrectly quoting both INT values produces the same result:

    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', '433283')\G;
    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: catalog_product_index_price
    type: range
    possible_keys: PRIMARY,IDX_CATALOGPRODUCTINDEXPRICE_ENTITYID
    key: PRIMARY
    key_len: 4
    ref: NULL
    rows: 19
    Extra: Using where
    1 row in set (0.00 sec)
    ```
  2. parhamr revised this gist Oct 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SQLexample.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Removing quotes from an INT column allows MySQL to use the index and this can reduce rows scanned by __99.997 percent__. Example from Magento 1.12 on a production database:
    Removing quotes from an INT column allows MySQL to use the index and this can reduce rows scanned by __99.997 percent__. Example from Magento 1.12 on a production database; the query takes nearly a second to execute:

    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', 433283)\G;
  3. parhamr revised this gist Oct 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SQLexample.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Removing quotes from an INT column allows MySQL to use the index and this can reduce rows scanned by __99.997 percent__. Example from Magento 1.12:
    Removing quotes from an INT column allows MySQL to use the index and this can reduce rows scanned by __99.997 percent__. Example from Magento 1.12 on a production database:

    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', 433283)\G;
  4. parhamr revised this gist Oct 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SQLexample.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Removing the quotes from the INT column allows MySQL to use the index and this reduces the rows scanned by __99.997 percent__. Example from Magento 1.12:
    Removing quotes from an INT column allows MySQL to use the index and this can reduce rows scanned by __99.997 percent__. Example from Magento 1.12:

    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', 433283)\G;
  5. parhamr revised this gist Oct 16, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion SQLexample.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Removing the quotes from the INT column allows MySQL to use the index and this reduces the rows scanned by __99.997 percent__. Example from Magento 1.12:

    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', 433283)\G;
    *************************** 1. row ***************************
    @@ -28,4 +30,3 @@ possible_keys: PRIMARY,IDX_CATALOGPRODUCTINDEXPRICE_ENTITYID
    1 row in set (0.00 sec)
    ```

    Removing the quotes from the INT column allows MySQL to use the index and this reduces the rows scanned by 99.997 percent.
  6. parhamr created this gist Oct 16, 2013.
    31 changes: 31 additions & 0 deletions SQLexample.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    ```sql
    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', 433283)\G;
    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: catalog_product_index_price
    type: ALL
    possible_keys: NULL
    key: NULL
    key_len: NULL
    ref: NULL
    rows: 773625
    Extra: Using where
    1 row in set (0.00 sec)

    mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN(433284, 433283)\G;
    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: catalog_product_index_price
    type: range
    possible_keys: PRIMARY,IDX_CATALOGPRODUCTINDEXPRICE_ENTITYID
    key: PRIMARY
    key_len: 4
    ref: NULL
    rows: 19
    Extra: Using where
    1 row in set (0.00 sec)
    ```

    Removing the quotes from the INT column allows MySQL to use the index and this reduces the rows scanned by 99.997 percent.