Re: Possible optimisation: push down SORT and LIMIT nodes

2018-06-01 Thread Rui DeSousa
True… but in that case it needs to be more expressive. i.e. with d as ( select date from inventory order by date limit 10 ), df as ( select distinct date from d ) select i.date, a.name, i.quantity from inventory i join asset a on a.id = i.id_asset where i.date in (select date from df)

Re: Possible optimisation: push down SORT and LIMIT nodes

2018-06-01 Thread Chris Wilson
Hi Rui, Unfortunately sorting and limiting the CTE doesn't work properly, because exactly which 100 rows are selected depends on values in the asset table, which are not known at the time that the cte is evaluated. I can work around it for our case by querying for the unique dates that make it

Re: Possible optimisation: push down SORT and LIMIT nodes

2018-06-01 Thread Rui DeSousa
In the meantime you can force it with CTE. with inv as ( select id_asset , inventory.date , quantity from inventory order by inventory.date limit 100 ) select inv.date, asset.name, inv.quantity from inv join asset on id_asset = asset.id order by inv.date, asset.name ; > On Jun 1,