ANALYZE TABLE
Van toepassing op: Databricks SQL Databricks Runtime
De ANALYZE TABLE
instructie verzamelt geschatte statistieken over een specifieke tabel of alle tabellen in een opgegeven schema.
Deze statistieken worden gebruikt door de queryoptimalisatie om een optimaal queryplan te genereren.
Omdat ze verouderd kunnen raken als gegevenswijzigingen, worden deze statistieken niet gebruikt om query's rechtstreeks te beantwoorden.
Verouderde statistieken zijn nog steeds nuttig voor de queryoptimalisatie bij het maken van een queryplan.
Syntaxis
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 ]
Parameters
-
Identificeert de tabel die moet worden geanalyseerd. De naam mag geen tijdelijke specificatie of pad bevatten. Als de tabel niet kan worden gevonden, genereert Azure Databricks een TABLE_OR_VIEW_NOT_FOUND fout.
-
De opdracht kan eventueel worden beperkt tot een subset van partities.
Deze component wordt niet ondersteund voor Delta Lake-tabellen.
DELTA
Van toepassing op: Databricks SQL Databricks Runtime 14.3 LTS en hoger
Hiermee worden statistieken die zijn opgeslagen in het Delta-logboek opnieuw berekend voor de kolommen die zijn geconfigureerd voor het verzamelen van statistieken in een Delta-tabel.
Wanneer het
DELTA
trefwoord is opgegeven, worden normale statistieken voor de queryoptimalisatie niet verzameld.Databricks raadt u aan om uit te voeren nadat u nieuwe kolommen hebt ingesteld
ANALYZE TABLE table_name COMPUTE DELTA STATISTICS
voor het overslaan van gegevens om statistieken voor alle rijen in een tabel bij te werken. Voor geoptimaliseerde prestaties voert u de opdracht uitANALYZE TABLE table_name COMPUTE STATISTICS
om het queryplan bij te werken nadat de deltalogboekupdate is voltooid.[ NOSCAN | FOR COLUMNS col [, ...] | VOOR ALLE KOLOMMEN ]
Als er geen analyseoptie is opgegeven,
ANALYZE TABLE
verzamelt u het aantal rijen en grootte van de tabel in bytes.NOSCAN
Verzamel alleen de grootte van de tabel in bytes (waarvoor de hele tabel niet hoeft te worden gescand).
FOR COLUMNS col [, ...] | VOOR ALLE KOLOMMEN
Verzamel kolomstatistieken voor elke opgegeven kolom of voor elke kolom, evenals tabelstatistieken.
Kolomstatistieken worden niet ondersteund in combinatie met de
PARTITION
component.
{ FROM
|
IN } schema_nameHiermee geeft u de naam van het schema dat moet worden geanalyseerd. Zonder schemanaam
ANALYZE TABLES
worden alle tabellen in het huidige schema verzameld die de huidige gebruiker heeft gemachtigd om te analyseren.
Voorbeelden
> 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;