|
1 | 1 | -- This file and its contents are licensed under the Timescale License.
|
2 | 2 | -- Please see the included NOTICE for copyright information and
|
3 | 3 | -- LICENSE-TIMESCALE for a copy of the license.
|
| 4 | +\set EXPLAIN 'EXPLAIN (costs off, timing off, summary off, analyze)' |
4 | 5 | CREATE OR REPLACE VIEW compressed_chunk_info_view AS
|
5 | 6 | SELECT
|
6 | 7 | h.schema_name AS hypertable_schema,
|
@@ -2944,106 +2945,215 @@ EXPLAIN (analyze, timing off, costs off, summary off) DELETE FROM test_meta_filt
|
2944 | 2945 | Rows Removed by Filter: 10
|
2945 | 2946 | (8 rows)
|
2946 | 2947 |
|
2947 |
| --- test commutator handling in compressed dml constraints |
2948 |
| -CREATE TABLE test_commutator(time timestamptz NOT NULL, device text); |
2949 |
| -SELECT table_name FROM create_hypertable('test_commutator', 'time'); |
2950 |
| - table_name |
2951 |
| ------------------ |
2952 |
| - test_commutator |
2953 |
| -(1 row) |
2954 |
| - |
2955 |
| -INSERT INTO test_commutator SELECT '2020-01-01', 'a'; |
2956 |
| -INSERT INTO test_commutator SELECT '2020-01-01', 'b'; |
2957 |
| -INSERT INTO test_commutator SELECT '2020-01-01', 'c'; |
2958 |
| -ALTER TABLE test_commutator SET (timescaledb.compress, timescaledb.compress_segmentby='device'); |
2959 |
| -NOTICE: default order by for hypertable "test_commutator" is set to ""time" DESC" |
2960 |
| -SELECT compress_chunk(show_chunks('test_commutator')); |
| 2948 | +-- test expression pushdown in compressed dml constraints |
| 2949 | +CREATE TABLE test_pushdown(time timestamptz NOT NULL, device text); |
| 2950 | +SELECT table_name FROM create_hypertable('test_pushdown', 'time'); |
| 2951 | + table_name |
| 2952 | +--------------- |
| 2953 | + test_pushdown |
| 2954 | +(1 row) |
| 2955 | + |
| 2956 | +INSERT INTO test_pushdown SELECT '2020-01-01', 'a'; |
| 2957 | +INSERT INTO test_pushdown SELECT '2020-01-01', 'b'; |
| 2958 | +INSERT INTO test_pushdown SELECT '2020-01-01 05:00', 'c'; |
| 2959 | +CREATE TABLE devices(device text); |
| 2960 | +INSERT INTO devices VALUES ('a'), ('b'), ('c'); |
| 2961 | +ALTER TABLE test_pushdown SET (timescaledb.compress, timescaledb.compress_segmentby='device'); |
| 2962 | +NOTICE: default order by for hypertable "test_pushdown" is set to ""time" DESC" |
| 2963 | +SELECT compress_chunk(show_chunks('test_pushdown')); |
2961 | 2964 | compress_chunk
|
2962 | 2965 | ------------------------------------------
|
2963 | 2966 | _timescaledb_internal._hyper_39_79_chunk
|
2964 | 2967 | (1 row)
|
2965 | 2968 |
|
2966 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'a' = device; ROLLBACK; |
2967 |
| - QUERY PLAN |
2968 |
| --------------------------------------------------------------------------------------- |
| 2969 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE 'a' = device; ROLLBACK; |
| 2970 | + QUERY PLAN |
| 2971 | +------------------------------------------------------------------------------------ |
2969 | 2972 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
2970 | 2973 | Batches decompressed: 1
|
2971 | 2974 | Tuples decompressed: 1
|
2972 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
2973 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
2974 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=1 loops=1) |
| 2975 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 2976 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 2977 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=1 loops=1) |
2975 | 2978 | Filter: ('a'::text = device)
|
2976 | 2979 | (7 rows)
|
2977 | 2980 |
|
2978 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE device < 'c' ; ROLLBACK; |
2979 |
| - QUERY PLAN |
2980 |
| --------------------------------------------------------------------------------------- |
| 2981 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE device < 'c' ; ROLLBACK; |
| 2982 | + QUERY PLAN |
| 2983 | +------------------------------------------------------------------------------------ |
2981 | 2984 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
2982 | 2985 | Batches decompressed: 2
|
2983 | 2986 | Tuples decompressed: 2
|
2984 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
2985 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
2986 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=2 loops=1) |
| 2987 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 2988 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 2989 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=2 loops=1) |
2987 | 2990 | Filter: (device < 'c'::text)
|
2988 | 2991 | (7 rows)
|
2989 | 2992 |
|
2990 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'c' > device; ROLLBACK; |
2991 |
| - QUERY PLAN |
2992 |
| --------------------------------------------------------------------------------------- |
| 2993 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE 'c' > device; ROLLBACK; |
| 2994 | + QUERY PLAN |
| 2995 | +------------------------------------------------------------------------------------ |
2993 | 2996 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
2994 | 2997 | Batches decompressed: 2
|
2995 | 2998 | Tuples decompressed: 2
|
2996 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
2997 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
2998 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=2 loops=1) |
| 2999 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3000 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3001 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=2 loops=1) |
2999 | 3002 | Filter: ('c'::text > device)
|
3000 | 3003 | (7 rows)
|
3001 | 3004 |
|
3002 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'c' >= device; ROLLBACK; |
3003 |
| - QUERY PLAN |
3004 |
| --------------------------------------------------------------------------------------- |
| 3005 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE 'c' >= device; ROLLBACK; |
| 3006 | + QUERY PLAN |
| 3007 | +------------------------------------------------------------------------------------ |
3005 | 3008 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
3006 | 3009 | Batches decompressed: 3
|
3007 | 3010 | Tuples decompressed: 3
|
3008 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
3009 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
3010 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=3 loops=1) |
| 3011 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3012 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3013 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=3 loops=1) |
3011 | 3014 | Filter: ('c'::text >= device)
|
3012 | 3015 | (7 rows)
|
3013 | 3016 |
|
3014 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE device > 'b'; ROLLBACK; |
3015 |
| - QUERY PLAN |
3016 |
| --------------------------------------------------------------------------------------- |
| 3017 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE device > 'b'; ROLLBACK; |
| 3018 | + QUERY PLAN |
| 3019 | +------------------------------------------------------------------------------------ |
3017 | 3020 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
3018 | 3021 | Batches decompressed: 1
|
3019 | 3022 | Tuples decompressed: 1
|
3020 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
3021 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
3022 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=1 loops=1) |
| 3023 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3024 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3025 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=1 loops=1) |
3023 | 3026 | Filter: (device > 'b'::text)
|
3024 | 3027 | (7 rows)
|
3025 | 3028 |
|
3026 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'b' < device; ROLLBACK; |
3027 |
| - QUERY PLAN |
3028 |
| --------------------------------------------------------------------------------------- |
| 3029 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE device = CURRENT_USER; ROLLBACK; |
| 3030 | + QUERY PLAN |
| 3031 | +------------------------------------------------------------------------------------------ |
| 3032 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3033 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3034 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3035 | + -> Custom Scan (ChunkAppend) on test_pushdown (actual rows=0 loops=1) |
| 3036 | + Chunks excluded during startup: 0 |
| 3037 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=0 loops=1) |
| 3038 | + Filter: (device = CURRENT_USER) |
| 3039 | +(7 rows) |
| 3040 | + |
| 3041 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE 'b' < device; ROLLBACK; |
| 3042 | + QUERY PLAN |
| 3043 | +------------------------------------------------------------------------------------ |
3029 | 3044 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
3030 | 3045 | Batches decompressed: 1
|
3031 | 3046 | Tuples decompressed: 1
|
3032 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
3033 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
3034 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=1 loops=1) |
| 3047 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3048 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3049 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=1 loops=1) |
3035 | 3050 | Filter: ('b'::text < device)
|
3036 | 3051 | (7 rows)
|
3037 | 3052 |
|
3038 |
| -BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'b' <= device; ROLLBACK; |
3039 |
| - QUERY PLAN |
3040 |
| --------------------------------------------------------------------------------------- |
| 3053 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE 'b' <= device; ROLLBACK; |
| 3054 | + QUERY PLAN |
| 3055 | +------------------------------------------------------------------------------------ |
3041 | 3056 | Custom Scan (HypertableModify) (actual rows=0 loops=1)
|
3042 | 3057 | Batches decompressed: 2
|
3043 | 3058 | Tuples decompressed: 2
|
3044 |
| - -> Delete on test_commutator (actual rows=0 loops=1) |
3045 |
| - Delete on _hyper_39_79_chunk test_commutator_1 |
3046 |
| - -> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=2 loops=1) |
| 3059 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3060 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3061 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=2 loops=1) |
3047 | 3062 | Filter: ('b'::text <= device)
|
3048 | 3063 | (7 rows)
|
3049 | 3064 |
|
| 3065 | +-- cant pushdown OR atm |
| 3066 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE device = 'a' OR device = 'b'; ROLLBACK; |
| 3067 | + QUERY PLAN |
| 3068 | +------------------------------------------------------------------------------------ |
| 3069 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3070 | + Batches decompressed: 3 |
| 3071 | + Tuples decompressed: 3 |
| 3072 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3073 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3074 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=2 loops=1) |
| 3075 | + Filter: ((device = 'a'::text) OR (device = 'b'::text)) |
| 3076 | + Rows Removed by Filter: 1 |
| 3077 | +(8 rows) |
| 3078 | + |
| 3079 | +-- test stable function |
| 3080 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE time = timestamptz('2020-01-01 05:00'); ROLLBACK; |
| 3081 | + QUERY PLAN |
| 3082 | +------------------------------------------------------------------------------------------- |
| 3083 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3084 | + Batches decompressed: 1 |
| 3085 | + Tuples decompressed: 1 |
| 3086 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3087 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3088 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=1 loops=1) |
| 3089 | + Filter: ("time" = 'Wed Jan 01 05:00:00 2020 PST'::timestamp with time zone) |
| 3090 | +(7 rows) |
| 3091 | + |
| 3092 | +-- test sqlvaluefunction |
| 3093 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown WHERE device = substring(CURRENT_USER,length(CURRENT_USER)+1) || 'c'; ROLLBACK; |
| 3094 | + QUERY PLAN |
| 3095 | +----------------------------------------------------------------------------------------------------------------------------- |
| 3096 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3097 | + Batches decompressed: 1 |
| 3098 | + Tuples decompressed: 1 |
| 3099 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3100 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3101 | + -> Custom Scan (ChunkAppend) on test_pushdown (actual rows=1 loops=1) |
| 3102 | + Chunks excluded during startup: 0 |
| 3103 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=1 loops=1) |
| 3104 | + Filter: (device = ("substring"((CURRENT_USER)::text, (length((CURRENT_USER)::text) + 1)) || 'c'::text)) |
| 3105 | +(9 rows) |
| 3106 | + |
| 3107 | +-- no filtering in decompression |
| 3108 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown p USING devices d WHERE p.device=d.device; ROLLBACK; |
| 3109 | + QUERY PLAN |
| 3110 | +------------------------------------------------------------------------------------ |
| 3111 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3112 | + Batches decompressed: 3 |
| 3113 | + Tuples decompressed: 3 |
| 3114 | + -> Delete on test_pushdown p (actual rows=0 loops=1) |
| 3115 | + Delete on _hyper_39_79_chunk p_1 |
| 3116 | + -> Merge Join (actual rows=3 loops=1) |
| 3117 | + Merge Cond: (p_1.device = d.device) |
| 3118 | + -> Sort (actual rows=3 loops=1) |
| 3119 | + Sort Key: p_1.device |
| 3120 | + Sort Method: quicksort |
| 3121 | + -> Seq Scan on _hyper_39_79_chunk p_1 (actual rows=3 loops=1) |
| 3122 | + -> Sort (actual rows=3 loops=1) |
| 3123 | + Sort Key: d.device |
| 3124 | + Sort Method: quicksort |
| 3125 | + -> Seq Scan on devices d (actual rows=3 loops=1) |
| 3126 | +(15 rows) |
| 3127 | + |
| 3128 | +-- can filter in decompression even before executing join |
| 3129 | +BEGIN; :EXPLAIN DELETE FROM test_pushdown p USING devices d WHERE p.device=d.device AND d.device ='b' ; ROLLBACK; |
| 3130 | + QUERY PLAN |
| 3131 | +------------------------------------------------------------------------------------ |
| 3132 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3133 | + Batches decompressed: 1 |
| 3134 | + Tuples decompressed: 1 |
| 3135 | + -> Delete on test_pushdown p (actual rows=0 loops=1) |
| 3136 | + Delete on _hyper_39_79_chunk p_1 |
| 3137 | + -> Nested Loop (actual rows=1 loops=1) |
| 3138 | + -> Seq Scan on devices d (actual rows=1 loops=1) |
| 3139 | + Filter: (device = 'b'::text) |
| 3140 | + Rows Removed by Filter: 2 |
| 3141 | + -> Materialize (actual rows=1 loops=1) |
| 3142 | + -> Seq Scan on _hyper_39_79_chunk p_1 (actual rows=1 loops=1) |
| 3143 | + Filter: (device = 'b'::text) |
| 3144 | +(12 rows) |
| 3145 | + |
| 3146 | +-- test prepared statement |
| 3147 | +PREPARE q1(text) AS DELETE FROM test_pushdown WHERE device = $1; |
| 3148 | +BEGIN; :EXPLAIN EXECUTE q1('a'); ROLLBACK; |
| 3149 | + QUERY PLAN |
| 3150 | +------------------------------------------------------------------------------------ |
| 3151 | + Custom Scan (HypertableModify) (actual rows=0 loops=1) |
| 3152 | + Batches decompressed: 1 |
| 3153 | + Tuples decompressed: 1 |
| 3154 | + -> Delete on test_pushdown (actual rows=0 loops=1) |
| 3155 | + Delete on _hyper_39_79_chunk test_pushdown_1 |
| 3156 | + -> Seq Scan on _hyper_39_79_chunk test_pushdown_1 (actual rows=1 loops=1) |
| 3157 | + Filter: (device = 'a'::text) |
| 3158 | +(7 rows) |
| 3159 | + |
0 commit comments