@@ -997,11 +997,111 @@ SELECT count(*), min(label), max(label) FROM inserted;
997997-------+-------+------
998998 20 | d0:10 | d1:9
999999
1000+ -- RETURNING a system column falls back to the normal insert path, except
1001+ -- tableoid which the returning projection sets explicitly.
1002+ EXPLAIN (COSTS OFF, SUMMARY OFF, TIMING OFF)
1003+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1004+ FROM generate_series(1, 20) i RETURNING ctid;
1005+ WARNING: disabling direct compress because the RETURNING clause references system columns
1006+ --- QUERY PLAN ---
1007+ Custom Scan (ModifyHypertable)
1008+ Direct Compress: false
1009+ -> Insert on dc_ret
1010+ -> Function Scan on generate_series i
1011+
1012+ EXPLAIN (COSTS OFF, SUMMARY OFF, TIMING OFF)
1013+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1014+ FROM generate_series(1, 20) i RETURNING xmin;
1015+ WARNING: disabling direct compress because the RETURNING clause references system columns
1016+ --- QUERY PLAN ---
1017+ Custom Scan (ModifyHypertable)
1018+ Direct Compress: false
1019+ -> Insert on dc_ret
1020+ -> Function Scan on generate_series i
1021+
1022+ EXPLAIN (COSTS OFF, SUMMARY OFF, TIMING OFF)
1023+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1024+ FROM generate_series(1, 20) i RETURNING cmin;
1025+ WARNING: disabling direct compress because the RETURNING clause references system columns
1026+ --- QUERY PLAN ---
1027+ Custom Scan (ModifyHypertable)
1028+ Direct Compress: false
1029+ -> Insert on dc_ret
1030+ -> Function Scan on generate_series i
1031+
1032+ EXPLAIN (COSTS OFF, SUMMARY OFF, TIMING OFF)
1033+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1034+ FROM generate_series(1, 20) i RETURNING xmax;
1035+ WARNING: disabling direct compress because the RETURNING clause references system columns
1036+ --- QUERY PLAN ---
1037+ Custom Scan (ModifyHypertable)
1038+ Direct Compress: false
1039+ -> Insert on dc_ret
1040+ -> Function Scan on generate_series i
1041+
1042+ EXPLAIN (COSTS OFF, SUMMARY OFF, TIMING OFF)
1043+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1044+ FROM generate_series(1, 20) i RETURNING cmax;
1045+ WARNING: disabling direct compress because the RETURNING clause references system columns
1046+ --- QUERY PLAN ---
1047+ Custom Scan (ModifyHypertable)
1048+ Direct Compress: false
1049+ -> Insert on dc_ret
1050+ -> Function Scan on generate_series i
1051+
1052+ -- tableoid stays on the direct compress path
1053+ EXPLAIN (COSTS OFF, SUMMARY OFF, TIMING OFF)
1054+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1055+ FROM generate_series(1, 20) i RETURNING tableoid;
1056+ --- QUERY PLAN ---
1057+ Custom Scan (ModifyHypertable)
1058+ Direct Compress: true
1059+ -> Insert on dc_ret
1060+ -> Function Scan on generate_series i
1061+
1062+ -- ctid falls back and returns real tuple ids
1063+ WITH inserted AS (
1064+ INSERT INTO dc_ret SELECT '2025-01-01'::timestamptz + (i * INTERVAL '1 day'), 'd' || (i % 2)::text, i
1065+ FROM generate_series(1, 20) i RETURNING ctid AS c, val
1066+ )
1067+ SELECT count(*), bool_and(c IS NOT NULL), min(val), max(val) FROM inserted;
1068+ WARNING: disabling direct compress because the RETURNING clause references system columns
1069+ count | bool_and | min | max
1070+ -------+----------+-----+-----
1071+ 20 | t | 1 | 20
1072+
1073+ -- tableoid on the direct compress path holds the target chunk (all 20 rows
1074+ -- land in one chunk, so every RETURNING row reports the same chunk)
1075+ INSERT INTO dc_ret SELECT '2025-06-01'::timestamptz + (i * INTERVAL '1 minute'), 'd' || (i % 2)::text, i
1076+ FROM generate_series(1, 20) i RETURNING tableoid::regclass AS chunk;
1077+ chunk
1078+ ------------------------------------------
1079+ _timescaledb_internal._hyper_16_67_chunk
1080+ _timescaledb_internal._hyper_16_67_chunk
1081+ _timescaledb_internal._hyper_16_67_chunk
1082+ _timescaledb_internal._hyper_16_67_chunk
1083+ _timescaledb_internal._hyper_16_67_chunk
1084+ _timescaledb_internal._hyper_16_67_chunk
1085+ _timescaledb_internal._hyper_16_67_chunk
1086+ _timescaledb_internal._hyper_16_67_chunk
1087+ _timescaledb_internal._hyper_16_67_chunk
1088+ _timescaledb_internal._hyper_16_67_chunk
1089+ _timescaledb_internal._hyper_16_67_chunk
1090+ _timescaledb_internal._hyper_16_67_chunk
1091+ _timescaledb_internal._hyper_16_67_chunk
1092+ _timescaledb_internal._hyper_16_67_chunk
1093+ _timescaledb_internal._hyper_16_67_chunk
1094+ _timescaledb_internal._hyper_16_67_chunk
1095+ _timescaledb_internal._hyper_16_67_chunk
1096+ _timescaledb_internal._hyper_16_67_chunk
1097+ _timescaledb_internal._hyper_16_67_chunk
1098+ _timescaledb_internal._hyper_16_67_chunk
1099+
10001100-- rows were actually inserted
10011101SELECT count(*) FROM dc_ret;
10021102 count
10031103-------
1004- 40
1104+ 80
10051105
10061106RESET timescaledb.enable_direct_compress_insert;
10071107DROP TABLE dc_ret;
0 commit comments