Hi Phillip.a.a is the primary key on table a and b.b is the foreign key on table b. Tabela "public.a" +--------+---------+---------------+ | Coluna | Tipo | Modificadores | +--------+---------+---------------+ | a | integer | não nulo | | b | integer | | +--------+---------+---------------+ Índices: "a_pkey" PRIMARY KEY, btree (a) Referenciada por: TABLE "b" CONSTRAINT "b_b_fkey" FOREIGN KEY (b) REFERENCES a(a) Tabela "public.b" +--------+---------+---------------+ | Coluna | Tipo | Modificadores | +--------+---------+---------------+ | a | integer | não nulo | | b | integer | | +--------+---------+---------------+ Índices: "b_pkey" PRIMARY KEY, btree (a) Restrições de chave estrangeira: "b_b_fkey" FOREIGN KEY (b) REFERENCES a(a)
It's the question. In the company I work with, one of my clients asked me: "Why PostgreSQL does not remove rows with null in column b (table b), before joining, since these rows have no corresponding in table a?" I gave the suggestion to put the IS NOT NULL in the WHERE statement, but HE can't modify the query in the application. I did the tests with Oracle and it uses a predicate in the query plan, removing the lines where b.b is null. In Oracle, it´s the same plan, with and without IS NOT NULL in the WHERE statement. -- Clailson Soares Dinízio de Almeida On 19/01/2017 09:34, Phillip Couto
wrote:
NULL is still a value that may be paired with a NULL in a.a |