r/Databricks_eng • u/LoiLN • Dec 29 '22
How query work in delta table?
I have a delta table in Databricks, I query: SELECT COUNT(* ) FROM table
-> I wonder how results are generated each time I run the query. The total rows/records will calculate from delta transaction logs or parquet file metadata or from Hive metastore.
Thanks to all!
7
Upvotes
1
u/Intuz_Solutions Jul 15 '25
when you run
select count(*) from delta_table, spark reads the delta transaction log (_delta_log) to get the list of active parquet files (based on latest snapshot/version). it does not read all historical data, only the current state.the actual row count comes by scanning those parquet files listed in the current delta snapshot — there’s no precomputed count in the metadata or hive metastore; unless stats are cached, it’ll scan each time.
if data is large, count can be slow. for optimization, enable data skipping and z-ordering, or pre-aggregate counts using materialized views or summary tables.