Skip to content

Instantly share code, notes, and snippets.

@msdousti
Last active October 27, 2023 14:13
Show Gist options
  • Save msdousti/3332bf1ba7c08482f67f24f655204814 to your computer and use it in GitHub Desktop.
Save msdousti/3332bf1ba7c08482f67f24f655204814 to your computer and use it in GitHub Desktop.
create table test
as
select id, random() > 0.5 as to_be
from generate_series(1, 10000000) as id;
CREATE INDEX IF NOT EXISTS idx_1
ON test (id)
WHERE to_be = true;
CREATE INDEX IF NOT EXISTS idx_2
ON test (id)
WHERE to_be = false;
-- Without to_be or not to_be
explain
select *
from test
where id = 1;
-- With to_be or not to_be
explain
select *
from test
where id = 1 and (to_be or not to_be);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment