Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding byte data and storing as TEXT vs storing in BYTEA in PostgreSQL

Tags:

sql

postgresql

I have some byte data(millions of rows), and currently, I am converting to base64 first, and storing it as TEXT. The data is indexed on a row that contains base64 data. I assume Postgres does the conversion to base64 itself.
Will it be faster if I store using BYTEA data type instead? How will the indexed queries be affected on two data types?

like image 894
Shubham Chaudhary Avatar asked Jan 11 '18 13:01

Shubham Chaudhary


Video Answer


1 Answers

Converting bytes to text using Base64 will consume 33% more space than bytes. Even this would be faster, you will use quite more space on disk. Loading and storing data should be slower as well. I see no advantage in doing that.

Postgres supports indices on BYTEA columns. Since the bytes are shorter than the text, byte columns with indexes should be faster than text columns with indices as well.

like image 110
clemens Avatar answered Oct 13 '22 12:10

clemens