2016-04-22 17:02 GMT+03:00 Mathias Kunter <mathiaskunter@gmail.com>:
> EXPLAIN SELECT * FROM book WHERE name = 'Harry Potter' OR authorId IN
> (SELECT id FROM author WHERE surname = 'Rowling');
> QUERY PLAN
>
> -------------------------------------------------------------------------------------------
> Seq Scan on book (cost=13.68..26792.88 rows=576709 width=40)
> ...
>
> EXPLAIN SELECT * FROM book WHERE name = 'Harry Potter' UNION SELECT * FROM
> book WHERE authorId IN (SELECT id FROM author WHERE surname = 'Rowling');
> QUERY PLAN
>
> ------------------------------------------------------------------------------------------------------------
> HashAggregate (cost=454.87..455.99 rows=112 width=29)
>
Queries return different number of rows, meaning they're not fully
equivalent.
Can you provide full DDL for the tables, constraints and indexes in use?
--
Victor Y. Yegorov