CREATE TABLE tbl42 AS (
	SELECT
		gs % 1000 AS x,
		(gs % 10 + (gs/10::int4) % 10) % 10 AS y,
		(gs / 100)::int4 AS z
	FROM generate_series(1,1000) AS gs
);
INSERT INTO tbl42 (
	SELECT gs,gs,gs FROM generate_series(1000,2000) AS gs
);

CREATE UNIQUE INDEX good ON tbl42 (x,y,z);
CREATE INDEX bad ON tbl42(x);
ANALYZE tbl42;

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM tbl42 WHERE x=1 AND y=1 AND z=1;

DROP INDEX good,bad CASCADE;
CREATE INDEX bad ON tbl42(x);
CREATE UNIQUE INDEX good ON tbl42 (x,y,z);
ANALYZE tbl42;

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM tbl42 WHERE x=1 AND y=1 AND z=1;

-- Clean up
DROP TABLE tbl42 CASCADE;
