Come applicare un limite o un timeout alle query

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

Questo articolo illustra i diversi metodi che possono essere usati per applicare un limite o un timeout alle query in MariaDB.

LIMIT

SELECT ... LIMIT num_righe
or
SELECT ... LIMIT scarto, num_righe
or
SELECT ... LIMIT num_righe OFFSET scarto

La clausola LIMIT riduce il numero di righe restituite.

MariaDB starting with 10.0.0

LIMIT ROWS EXAMINED

SELECT ... LIMIT ROWS EXAMINED num_righe;

Ferma la query dopo che sono state esaminate 'num_righe'.

SQL_SAFE_UPDATES

Se la variabile SQL_SAFE_UPDATES è impostata, non sarà possibile eseguire un'istruzione UPDATE o DELETE a meno che non si specifichi una clausola WHERE con una condizione su una chiave, oppure una clausola LIMIT (o entrambe).

SET @@SQL_SAFE_UPDATES=1
UPDATE nome_tab SET colonna_non_chiave=val;
-> ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

SQL_SELECT_LIMIT

SQL_SELECT_LIMIT applica automaticamente LIMIT num_righe a tutte le query SELECT.

SET @@SQL_SELECT_LIMIT=1000
SELECT * from grande_tabella;

...si comporta come:

SELECT * from big_table LIMIT 1000;

SQL_MAX_JOIN_SIZE

Se SQL_MAX_JOIN_SIZE è impostata, limiterà tutte le istruzioni SELECT che probabilmente dovranno esaminare più di SQL_MAX_JOIN_SIZE righe.

SET @@SQL_MAX_JOIN_SIZE=1000;
SELECT count(null_column) from grande_tabella;
->ERROR 1104 (42000): The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay

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.