Event Timeline
Comment Actions
FTR, using order by age():
guest@softwareheritage => explain analyze select * from origin_visit inner join origin on origin_visit.origin=origin.id where origin.url='https://pypi.org/project/cubicweb-preview/' order by abs(extract(epoch from age(date, '2020-01-01'))) limit 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=1978.19..1978.19 rows=1 width=89) (actual time=457.474..457.478 rows=1 loops=1) -> Sort (cost=1978.19..1978.21 rows=7 width=89) (actual time=457.472..457.474 rows=1 loops=1) Sort Key: (abs(date_part('epoch'::text, age(origin_visit.date, '2020-01-01 00:00:00+00'::timestamp with time zone)))) Sort Method: top-N heapsort Memory: 25kB -> Nested Loop (cost=1.27..1978.16 rows=7 width=89) (actual time=1.542..455.003 rows=814 loops=1) -> Index Scan using origin_url_idx on origin (cost=0.70..4.71 rows=1 width=53) (actual time=0.111..0.114 rows=1 loops=1) Index Cond: (url = 'https://pypi.org/project/cubicweb-preview/'::text) -> Index Scan using origin_visit_pkey on origin_visit (cost=0.58..1963.05 rows=1034 width=28) (actual time=1.417..450.791 rows=814 loops=1) Index Cond: (origin = origin.id) Planning Time: 1.032 ms Execution Time: 457.550 ms (11 rows)