--
-- JGH heapify_siftdown performance
--

-- Random
CREATE TABLE jgh (i integer);
INSERT INTO jgh (i) SELECT 20000 * random() FROM generate_series(1, 20000);
VACUUM ANALYZE jgh;
set work_mem to 1024;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 40000 * random() FROM generate_series(1, 40000);
VACUUM ANALYZE jgh;
set work_mem to 2048;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 80000 * random() FROM generate_series(1, 80000);
VACUUM ANALYZE jgh;
set work_mem to 4096;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 160000 * random() FROM generate_series(1, 160000);
VACUUM ANALYZE jgh;
set work_mem to 8192;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 320000 * random() FROM generate_series(1, 320000);
VACUUM ANALYZE jgh;
set work_mem to 16384;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 640000 * random() FROM generate_series(1, 640000);
VACUUM ANALYZE jgh;
set work_mem to 32768;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 1280000 * random() FROM generate_series(1, 1280000);
VACUUM ANALYZE jgh;
set work_mem to 65536;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 2560000 * random() FROM generate_series(1, 2560000);
VACUUM ANALYZE jgh;
set work_mem to 131072;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 5120000 * random() FROM generate_series(1, 5120000);
VACUUM ANALYZE jgh;
set work_mem to 262144;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 10240000 * random() FROM generate_series(1, 10240000);
VACUUM ANALYZE jgh;
set work_mem to 524288;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 20480000 * random() FROM generate_series(1, 20480000);
VACUUM ANALYZE jgh;
set work_mem to 1048576;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;

DROP TABLE jgh;

-- Presorted
CREATE TABLE jgh (i integer);
INSERT INTO jgh (i) SELECT * FROM generate_series(1, 20000);
VACUUM ANALYZE jgh;
set work_mem to 1024;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 40000);
VACUUM ANALYZE jgh;
set work_mem to 2048;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 80000);
VACUUM ANALYZE jgh;
set work_mem to 4096;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 160000);
VACUUM ANALYZE jgh;
set work_mem to 8192;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 320000);
VACUUM ANALYZE jgh;
set work_mem to 16384;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 640000);
VACUUM ANALYZE jgh;
set work_mem to 32768;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 1280000);
VACUUM ANALYZE jgh;
set work_mem to 65536;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 2560000);
VACUUM ANALYZE jgh;
set work_mem to 131072;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 5120000);
VACUUM ANALYZE jgh;
set work_mem to 262144;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 10240000);
VACUUM ANALYZE jgh;
set work_mem to 524288;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1, 20480000);
VACUUM ANALYZE jgh;
set work_mem to 1048576;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;

DROP TABLE jgh;

-- Reverse sorted
CREATE TABLE jgh (i integer);
INSERT INTO jgh (i) SELECT * FROM generate_series(20000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 1024;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(40000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 2048;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(80000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 4096;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(160000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 8192;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(320000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 16384;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(640000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 32768;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(1280000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 65536;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(2560000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 131072;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(5120000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 262144;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(10240000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 524288;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT * FROM generate_series(20480000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 1048576;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;

DROP TABLE jgh;

-- Constant
CREATE TABLE jgh (i integer);
INSERT INTO jgh (i) SELECT 0 FROM generate_series(20000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 1024;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(40000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 2048;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(80000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 4096;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(160000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 8192;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(320000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 16384;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(640000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 32768;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(1280000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 65536;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(2560000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 131072;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(5120000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 262144;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(10240000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 524288;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT 0 FROM generate_series(20480000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 1048576;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;

DROP TABLE jgh;

-- pipe-organ (full crossover)
CREATE TABLE jgh (i integer);
INSERT INTO jgh (i) SELECT case WHEN (j & 1 = 1) THEN j ELSE 20000-j END FROM generate_series(1, 20000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 1024;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 40000-j END FROM generate_series(1, 40000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 2048;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 80000-j END FROM generate_series(1, 80000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 4096;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 160000-j END FROM generate_series(1, 160000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 8192;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 320000-j END FROM generate_series(1, 320000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 16384;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 640000-j END FROM generate_series(1, 640000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 32768;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 1280000-j END FROM generate_series(1, 1280000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 65536;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 2560000-j END FROM generate_series(1, 2560000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 131072;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 5120000-j END FROM generate_series(1, 5120000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 262144;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 10240000-j END FROM generate_series(1, 10240000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 524288;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i integer);

INSERT INTO jgh (i) SELECT CASE WHEN (j & 1 = 1) THEN j ELSE 20480000-j END FROM generate_series(1, 20480000) AS j;
VACUUM ANALYZE jgh;
set work_mem to 1048576;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;

DROP TABLE jgh;

-- Random text
CREATE TABLE jgh (i text);
INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(20000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 1024;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(40000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 2048;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(80000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 4096;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(160000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 8192;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(320000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 16384;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(640000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 32768;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(1280000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 65536;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(2560000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 131072;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(5120000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 262144;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(10240000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 524288;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;
DROP TABLE jgh;
CREATE TABLE jgh (i text);

INSERT INTO jgh (i) SELECT md5(random()::text) FROM generate_series(20480000, 1, -1);
VACUUM ANALYZE jgh;
set work_mem to 1048576;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to off;
explain analyze SELECT * FROM jgh ORDER BY i;
set enable_siftdown_heapify to on;

DROP TABLE jgh;

