Search Postgresql Archives

substring on bit(n) and bytea types is slow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Queries like this:

SELECT substring(bitarray from (32 * (n - 1) + 1) for 32) -- bitarray is a column of type bit(64000000)
FROM array_test_bit
JOIN generate_series(1, 10000) n ON true;

SELECT substring(bytearr from (8 * (n - 1) + 1) for 8) -- bytearr is a column of type bytea
FROM array_test_bytea
JOIN generate_series(1, 10000) n ON true;

...are really slow. These take over a minute each and a postgres backend process uses 100% of a CPU while the query runs. The same thing in SQL Server 2014 (using varbinary(max) columns) runs fast - about 20 seconds for 4 million rows. Are byte/bit arrays just inherently slow in Postgres? Or is substring the wrong function to use for them?

The context is that I want to efficiently store many integers. The obvious answer is integer[], but most of my integers can fit into less than 32 bits, so I'd like to see if I can pack them more efficiently.

Regards,

Evgeny Morozov

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux