ANALYZE TABLE
Si applica a: Databricks SQL Databricks Runtime
L'istruzione ANALYZE TABLE
raccoglie statistiche stimate su una tabella specifica o su tutte le tabelle in uno schema specificato. Queste statistiche vengono usate da Query Optimizer per generare un piano di query ottimale.
L'ottimizzazione predittiva viene eseguita automaticamente su tabelle gestite dal Catalogo Unity ANALYZE
. Databricks consiglia di abilitare l'ottimizzazione predittiva per tutte le tabelle gestite di Unity Catalog per semplificare la manutenzione dei dati e ridurre i costi di archiviazione. Consulta Ottimizzazione predittiva per le tabelle gestite da Unity Catalog.
Sintassi
ANALYZE TABLE table_name [ PARTITION clause ]
COMPUTE [ DELTA ] STATISTICS [ NOSCAN | FOR COLUMNS col1 [, ...] | FOR ALL COLUMNS ]
ANALYZE TABLES [ { FROM | IN } schema_name ] COMPUTE STATISTICS [ NOSCAN ]
Parametri
-
Identifica la tabella da analizzare. Il nome non deve includere una specifica temporale o una specifica o un percorso di opzioni. Se la tabella non è stata trovata, Azure Databricks genera un errore di TABLE_OR_VIEW_NOT_FOUND.
-
Facoltativamente, limita il comando a un subset di partizioni.
Questa clausola non è supportata per le tabelle Delta Lake.
DELTA
Si applica a: Databricks SQL Databricks Runtime 14.3 LTS e versioni successive
Ricompila le statistiche archiviate nel log Delta per le colonne configurate per la raccolta di statistiche in una tabella Delta.
Quando si specifica la
DELTA
parola chiave , le statistiche normali per Query Optimizer non vengono raccolte.Databricks consiglia di eseguire
ANALYZE TABLE table_name COMPUTE DELTA STATISTICS
dopo aver impostato nuove colonne per il salto dei dati, per aggiornare le statistiche di tutte le righe di una tabella. Per ottimizzare le prestazioni, eseguireANALYZE TABLE table_name COMPUTE STATISTICS
per aggiornare il piano di query al termine dell'aggiornamento del log Delta.[ NOSCAN | FOR COLUMNS col [, ...] | PER TUTTI COLUMNS ]
Se non viene specificata alcuna opzione di analisi,
ANALYZE TABLE
raccoglie il numero di righe e dimensioni della tabella in byte.NOSCAN
Raccogliere solo le dimensioni della tabella in byte ( che non richiede l'analisi dell'intera tabella ).
FOR COLUMNS col [, ...] | PER TUTTI COLUMNS
Raccogliere le statistiche delle colonne per ogni colonna specificata o in alternativa per ogni colonna, nonché le statistiche delle tabelle.
Le statistiche delle colonne non sono supportate in combinazione con la clausola
PARTITION
.
{ FROM
|
IN } schema_nameSpecifica il nome dello schema da analizzare. Senza un nome di schema,
ANALYZE TABLES
raccoglie tutte le tabelle nello schema corrente a cui l'utente corrente ha l'autorizzazione per l'analisi.
Esempi
> CREATE TABLE students (name STRING, student_id INT) PARTITIONED BY (student_id);
> INSERT INTO students PARTITION (student_id = 111111) VALUES ('Mark');
> INSERT INTO students PARTITION (student_id = 222222) VALUES ('John');
> ANALYZE TABLE students COMPUTE STATISTICS NOSCAN;
> DESC EXTENDED students;
col_name data_type comment
-------------------- -------------------- -------
name string null
student_id int null
... ... ...
Statistics 864 bytes
... ... ...
> ANALYZE TABLE students COMPUTE STATISTICS;
> DESC EXTENDED students;
col_name data_type comment
-------------------- -------------------- -------
name string null
student_id int null
... ... ...
Statistics 864 bytes, 2 rows
... ... ...
-- Note: ANALYZE TABLE .. PARTITION is not supported for Delta tables.
> ANALYZE TABLE students PARTITION (student_id = 111111) COMPUTE STATISTICS;
> DESC EXTENDED students PARTITION (student_id = 111111);
col_name data_type comment
-------------------- -------------------- -------
name string null
student_id int null
... ... ...
Partition Statistics 432 bytes, 1 rows
... ... ...
OutputFormat org.apache.hadoop...
> ANALYZE TABLE students COMPUTE STATISTICS FOR COLUMNS name;
> DESC EXTENDED students name;
info_name info_value
-------------- ----------
col_name name
data_type string
comment NULL
min NULL
max NULL
num_nulls 0
distinct_count 2
avg_col_len 4
max_col_len 4
histogram NULL
> ANALYZE TABLES IN school_schema COMPUTE STATISTICS NOSCAN;
> DESC EXTENDED teachers;
col_name data_type comment
-------------------- -------------------- -------
name string null
teacher_id int null
... ... ...
Statistics 1382 bytes
... ... ...
> DESC EXTENDED students;
col_name data_type comment
-------------------- -------------------- -------
name string null
student_id int null
... ... ...
Statistics 864 bytes
... ... ...
> ANALYZE TABLES COMPUTE STATISTICS;
> DESC EXTENDED teachers;
col_name data_type comment
-------------------- -------------------- -------
name string null
teacher_id int null
... ... ...
Statistics 1382 bytes, 2 rows
... ... ...
> DESC EXTENDED students;
col_name data_type comment
-------------------- -------------------- -------
name string null
student_id int null
... ... ...
Statistics 864 bytes, 2 rows
... ... ...
> ANALYZE TABLE some_delta_table COMPUTE DELTA STATISTICS;