Hello,
Updating an empty table that has projections takes a relatively long time even though no action will be performed eventually. Can any one help understand this behaviour? why can't the optimizer tell that the table is empty when establishing the plan? How can one optimize this? Note that we can't tell in advance whether these tables will be empty or not.
Here is a simple example:
CREATE TABLE new_table1 LIKE table1 INCLUDING PROJECTIONS;
UPDATE new_table1 r
SET email=n.email
FROM table2 n
WHERE r.name = n.name;
-- OUTPUT
------
-- 0
-- (1 row)
-- Time: First fetch (1 row): 2722.300 ms. All rows formatted: 2722.337 ms
On an empty table that has no projection, the execution will be almost instant
CREATE TABLE new_table2 LIKE table1;
UPDATE new_table2 r
SET email=n.email
FROM table2 n
WHERE r.name = n.name;
-- OUTPUT
------
-- 0
-- (1 row)
-- Time: First fetch (1 row): 50.612 ms. All rows formatted: 50.641 ms
Many thanks,
Chaima BERRACHDI