andrew on Nostr: b=# with recursive h(blockhash,height) as ( select ...
b=# with recursive h(blockhash,height) as (
select '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'::sha256,0
union
select blocks.hash,height+1 from h,blocks where h.blockhash=prev
) select * from h;
Time: 1951.347 ms (00:01.951)
A bit of fun with recursive CTEs in PostgreSQL. Crazy fast if you think this is functionally a million JOINs between two tables with a million rows each.
select '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'::sha256,0
union
select blocks.hash,height+1 from h,blocks where h.blockhash=prev
) select * from h;
Time: 1951.347 ms (00:01.951)
A bit of fun with recursive CTEs in PostgreSQL. Crazy fast if you think this is functionally a million JOINs between two tables with a million rows each.