Re: Performant queries on table with many boolean columns

From: Adam Brusselback <adambrusselback(at)gmail(dot)com>
To: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Performant queries on table with many boolean columns
Date: 2016-04-25 17:23:28
Message-ID: CAMjNa7dqiG4xDB8yGK47zyeRnqf_yJSMbLBihOeqZOg+oVXH8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

At that point would it be better to just use a boolean array?

Here is an example I just wrote up that does pretty damn fast searches.

SET work_mem = '256 MB';

CREATE TABLE test_bool AS
SELECT id, array_agg(random() < 0.85) as boolean_column
FROM generate_series(1, 100)
CROSS JOIN generate_series(1, 500000) id
GROUP BY id;

CREATE INDEX idx_test_bool ON test_bool (boolean_column);

VACUUM ANALYZE test_bool;

SELECT *
FROM test_bool
ORDER BY random()
LIMIT 10

SELECT id
FROM test_bool
WHERE boolean_column =
'{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,f,t,t,t,t,f,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,f,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,f,f,t,t,t,t,t,t,t,t,t,f,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,f}'

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Sven Kerkling 2016-04-26 10:13:03 Re: Performance problems with postgres and null Values?
Previous Message Merlin Moncure 2016-04-25 16:28:42 Re: Performant queries on table with many boolean columns