Strange behavior of limit clause in complex query

2022-06-08 Thread Paulo Silva
4485 written=504 -> Nested Loop (cost=0.86..41816103.19 rows=27943 width=12) (actual time=11037.143..183849.116 rows=5 loops=1) Buffers: shared hit=15414548 read=564485 written=504 -> Index Scan Backward using ix_ng_content_date on ng_content "Extent1" (cost=0.43..40616715.85 rows=2231839 width=12) (actual time=11027.808..183839.289 rows=5 loops=1) Filter: ((2 = id_status) AND (date_from <= LOCALTIMESTAMP) AND (date_to >= LOCALTIMESTAMP) AND (SubPlan 1)) Rows Removed by Filter: 4685618 Buffers: shared hit=15414533 read=564480 written=504 SubPlan 1 -> Index Only Scan using ix_ngx_tag_content on ngx_tag_content "Extent3" (cost=0.43..8.46 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=4484963) Index Cond: (("TagId" = 337139) AND ("ContentId" = "Extent1".id)) Heap Fetches: 5 Buffers: shared hit=13454890 read=4 -> Index Scan using ng_path_content_id_content_idx on ng_path_content "Extent2" (cost=0.43..0.53 rows=1 width=4) (actual time=1.956..1.958 rows=1 loops=5) Index Cond: (id_content = "Extent1".id) Filter: (id_path = ANY ('{27495,27554,27555}'::integer[])) Buffers: shared hit=15 read=5 Planning: Buffers: shared hit=474 read=76 Planning Time: 113.080 ms Execution Time: 183849.283 ms Can someone help me understand what's going on? -- Paulo Silva

Re: Strange behavior of limit clause in complex query

2022-06-08 Thread Paulo Silva
Hi, The problem is that the query is generated by the framework, I'm not sure if I can change anything on it. Any other way to influence planner? Regards Ranier Vilela escreveu no dia quarta, 8/06/2022 à(s) 12:40: > Em qua., 8 de jun. de 2022 às 05:44, Paulo Silva > escreveu: &