Re: Query plan: SELECT vs INSERT from same select

2019-07-24 Thread Alban Hertroys
> On 23 Jul 2019, at 22:29, Alexander Voytsekhovskyy > wrote: > > I have quite complicated query: > > SELECT axis_x1, axis_y1, SUM(delivery_price) as v_1 FROM ( > SELECT to_char(delivery_data.delivery_date, '-MM') as axis_x1, > clients.id_client as axis_y1, delivery_data.amount * produc

Re: Query plan: SELECT vs INSERT from same select

2019-07-23 Thread Tom Lane
[ please keep the list cc'd ] Alexander Voytsekhovskyy writes: > Sorry again > here is both links: > https://explain.depesz.com/s/AEWj > https://explain.depesz.com/s/CHwF Don't think I believe that those are the same query --- there's a CTE in the second one that doesn't appear in the first, and

Re: Query plan: SELECT vs INSERT from same select

2019-07-23 Thread Tom Lane
Alexander Voytsekhovskyy writes: > You can see explain analyze verbose here: > https://explain.depesz.com/s/AEWj > The problem is, when i wrap it to > A) > INSERT INTO norepl_1542_result (axis_x1, axis_y1, v_1) > SELECT SAME QUERY > OR even > B) > WITH rows AS ( > ... SAME SELECT QUERY ..

Re: Query plan: SELECT vs INSERT from same select

2019-07-23 Thread Igor Korot
Hi, On Tue, Jul 23, 2019 at 3:29 PM Alexander Voytsekhovskyy wrote: > > I have quite complicated query: > > SELECT axis_x1, axis_y1, SUM(delivery_price) as v_1 FROM ( > SELECT to_char(delivery_data.delivery_date, '-MM') as axis_x1, > clients.id_client as axis_y1, delivery_data.amount * prod

Query plan: SELECT vs INSERT from same select

2019-07-23 Thread Alexander Voytsekhovskyy
I have quite complicated query: SELECT axis_x1, axis_y1, SUM(delivery_price) as v_1 FROM ( SELECT to_char(delivery_data.delivery_date, '-MM') as axis_x1, clients.id_client as axis_y1, delivery_data.amount * production_price.price * groups.discount as delivery_price FROM delivery_data JOIN cl