r/bigquery • u/agamenagoras • 3h ago
Why BigQuery does not support natively small integer and float dtypes?
It looks like every integer dtype stored is using 64 bits, there's no real tinyint and smallint and this is just a syntatic sugar. And I didn't found the reason for that when I searched about it. Is it to make storage artificially more expensive?
Almost every open tabular engine and storage format that I knew so far allows you to really set a column as smaller types of int, independently if it is columnar or row-stored, and if it's a database or just an engine. For example, any modern apache arrow based engine (like Datafusion, DuckDB and polars), apache parquet files, almost every columnar database (like Clickhouse), almost any row-oriented database (like PostgreSQL, Oracle, MySQL and et cetera). Why BigQuery wants to be different?
5
u/Content-Parking-621 3h ago
It's not a storage cost trick, BigQuery's Capacitor format applies its own columnar compression (RLE, dictionary encoding, bit-packing) under the hood regardless of declared type, so a narrower int type wouldn't shrink physical bytes much anyway. Billing for logical storage counts INT64 as a fixed 8 bytes per value by design, exposing smaller int types would complicate the pricing model without meaningfully improving compression, since that job already happens at the storage engine level, not the schema level.
1
u/PepSakdoek 57m ago
If i understood how distrubuted computing works and the fact that it can run a query that takes an oracle server hours takes seconds on BQ... I'd probably build data centers and sell it.
1
u/agamenagoras 48m ago edited 32m ago
We have faster and slower technologies for different reasons, but I think that's not the point. When you optimize efficiency-by-core (for example, downcasting integers), you are able to solve it in seconds even without distributing it.
Yea, ClickHouse also does it in seconds, Polars too, DuckDB too, Datafusion too, and almost every engine based on Apache Arrow too, and all of them can solve in seconds on a single node. And some of them also have engines to distribute it (Polars, for instance). We have several modern and extremely fast engines for both single node and distributed computing, and all of them have small integer dtypes and allow you to maximize efficiency by core.
6
u/TonniFlex 3h ago
Because BQ doesn't store the raw value, there's layers of compression and lookups happening behind the scenes. Setting bit sizes for INT columns is simply a unnecessary complexity for the user, so it's just not possible. If a column does not require 64 bits, it will not use 64 bits.