· 4 years ago · Jul 05, 2021, 07:28 AM
1CREATE SCHEMA IF NOT EXISTS test;
2CREATE TABLE IF NOT EXISTS test.study (
3 id bigserial PRIMARY KEY,
4 facts text NOT NULL
5);
6CREATE TABLE IF NOT EXISTS test.report (
7 id bigserial PRIMARY KEY,
8 variables text NOT NULL
9);
10INSERT INTO test.study(facts) values ('abc', 'def');
11INSERT INTO test.report(variables) values ('abc', 'def');
12
13-- forces it to use indexes
14SET enable_seqscan = false;
15
16EXPLAIN ANALYZE
17SELECT s.id
18FROM test.study s JOIN test.report r ON s.id = r.id
19WHERE s.facts = 'abc' OR r.variables = 'def';