Chiavi Estese

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Sintassi

Per abilitare:

set optimizer_switch='extended_keys=on';

Per disabilitare:

set optimizer_switch='extended_keys=off';

Il default è 'extended_keys=off' .

Spiegazione

Le Chiavi Estese, introdotte in MariaDB 5.5, sono un'ottimizzazione che fa uso di componenti già esistenti delle chiavi di InnoDB/XtraDB per generare piani di esecuzione più efficienti. L'uso di questi componenti in molti casi permette al server di risolvere una query utilizzando esclusivamente ricerche basate sugli indici.

Le Chiavi Estese si possono usare con:

  • accessi ref e eq-ref
  • scansioni di intervalli
  • scansioni index-merge
  • scansioni allargate
  • ottimizzazioni min/max

Examples

An example of how extended keys could be employed for a query built over a DBT-3/TPC-H database with one added index defined on p_retailprice:

select o_orderkey
from part, lineitem, orders
where p_retailprice > 2095 and o_orderdate='1992-07-01'
      and o_orderkey=l_orderkey and p_partkey=l_partkey;

The above query asks for the orderkeys of the orders placed on 1992-07-01 which contain parts with a retail price greater than $2095.

Using Extended Keys, the query could be executed by the following execution plan:

  1. Scan the entries of the index i_p_retailprice where p_retailprice>2095 and read p_partkey values from the extended keys.
  2. For each value p_partkey make an index look-up into the table lineitem employing index i_l_partkey and fetch the values of l_orderkey from the extended index.
  3. For each fetched value of l_orderkey, append it to the date '1992-07-01' and use the resulting key for an index look-up by index i_o_orderdate to fetch the values of o_orderkey from the found index entries.

All access methods of this plan do not touch table rows, which results in much better performance.

Here is the explain output for the above query:

MariaDB [dbt3sf10]> explain
   -> select o_orderkey
   ->   from part, lineitem, orders
   ->   where p_retailprice > 2095 and o_orderdate='1992-07-01'
   ->         and o_orderkey=l_orderkey and p_partkey=l_partkey\G
*************************** 1. row ***************************
          id: 1
 select_type: SIMPLE
       table: part
        type: range
possible_keys: PRIMARY,i_p_retailprice
         key: i_p_retailprice
     key_len: 9
         ref: NULL
        rows: 100
       Extra: Using where; Using index
*************************** 2. row ***************************
          id: 1
 select_type: SIMPLE
       table: lineitem
        type: ref
possible_keys: PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity
         key: i_l_partkey
     key_len: 5
         ref: dbt3sf10.part.p_partkey
        rows: 15
       Extra: Using index
*************************** 3. row ***************************
          id: 1
 select_type: SIMPLE
       table: orders
        type: ref
possible_keys: PRIMARY,i_o_orderdate
         key: i_o_orderdate
     key_len: 8
         ref: const,dbt3sf10.lineitem.l_orderkey
        rows: 1
       Extra: Using index
3 rows in set (0.00 sec)

See Also

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.