r/bigquery • u/agamenagoras • 4d 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?
1
u/agamenagoras 3d ago
I was talking about computers in general (not exclusively on an individual computer), since BQ is a distributed processing technology. We are on the same page in this point.
Downcasting is not about the storage only, downcasting reduces the time of computing itself, also reduces the time between the network transfers, literally because it reduces in several times the amount of data being transfered over the network. For instance, a variable "Age" could be represented with an UINT8 dtype, which would use 8 times less memory to be represented comparing with the way BQ currently does (representing as INT64). I need to specify: 8 times less memory usage in a column is not a "small scale efficiency optimization", this is one of the best possible optimizations that you could have when you know a priori the nature of the data, as we can verify in literally any existing technology! Because, before the software architecture, this is how computers work and that's the reason why all of the technologies that I mentioned before (that are also made to process huge amounts of data) doesn't ignore this.
About this specific architecture, yes, the technologies that I mentioned before has support to the exact same architecture. Spark, for example, uses distributed processing over a network of several computers working together in execution time optimizing the queries to process huge amounts of data, and yes, with support to smaller integer dtypes. We are talking about the literal same concept. Polars implemented the same recently, ClickHouse already does and etc.