
create table gpolygon_circle_tbl as
select polygon(a.home_base) as poly,
	circle(b.home_base) as circ
from slow_emp4000 as a,
	lateral (select * from slow_emp4000 as b
			order by a.home_base <-> b.home_base limit 2) as b;

create table seqscan_result (id serial, poly polygon, circ circle);
create table indexscan_result (id serial, poly polygon, circ circle);

insert into seqscan_result
select row_number(*) over (), *
from (select * from gpolygon_circle_tbl
	order by poly <-> '(0,0)'::
	point, circ <-> '(200,300)'::point) as a;

create index on gpolygon_circle_tbl
using gist (poly, circ);

set enable_seqscan = false;

insert into indexscan_result
select row_number(*) over (), *
from (select * from gpolygon_circle_tbl
	order by poly <-> '(0,0)'::point, circ <-> '(200,300)'::point) as a;

-- Should not return a row.
select *
from seqscan_result join indexscan_result using (id)
where seqscan_result.poly::text != indexscan_result.poly::text or
		seqscan_result.circ::text != indexscan_result.circ::text;
