Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee169f8

Browse files
committed
Small fix
1 parenta831265 commitee169f8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

‎0065_uuid_v7_and_partitioning_timescaledb.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ create table my_table (
122122
);
123123
```
124124

125-
The default value`00000000-...00` for"id" is "fake" – it will always be replaced in trigger, based on the timestamp:
125+
The default value`00000000-...00` for`id` is "fake" – it will always be replaced in trigger, based on the timestamp:
126126

127127
```sql
128128
create or replacefunctiont_update_uuid() returns trigger
@@ -191,29 +191,33 @@ Child tables: _timescaledb_internal._hyper_2_3_chunk,
191191

192192
##Test queries – partition pruning
193193

194-
Now we just need to remember that`created_at` should always participate in queries, to let planner deal with as few
195-
partitions as possible – but knowing the`id` values, we can always reconstruct the`created_at` values, using
196-
`uuid_v7_to_ts()`:
194+
Now we just need to remember that`uuid_ts` should always participate in queries, to let planner deal with as few
195+
partitions as possible – but knowing the`id` values, we can always reconstruct the`uuid_ts` values, using
196+
`uuid_v7_to_ts()`. Note that I first disabled`seqscan` as the table`my_table` has too few rows, otherwise PostgreSQL
197+
may decide on preferring`seqscan` over index scan:
197198

198199
```sql
199-
test=# explain select * from my_table where created_at = uuid_v7_to_ts('00dc6ad0-9660-7b92-a95e-1d7afdaae659');
200+
test# set enable_seqscan = off;
201+
SET
202+
203+
test=# explain select * from my_table where uuid_ts = uuid_v7_to_ts('00dc6ad0-9660-7b92-a95e-1d7afdaae659');
200204
QUERY PLAN
201205
--------------------------------------------------------------------------------------------------------------------------
202206
Append (cost=0.14..8.16 rows=1 width=41)
203-
-> Index Scan using_hyper_5_11_chunk_my_table_created_at_idxon _hyper_5_11_chunk (cost=0.14..8.15 rows=1 width=41)
204-
Index Cond: (created_at='2000-01-01 00:01:00+00'::timestamp with time zone)
207+
-> Index Scan using_hyper_5_11_chunk_my_table_uuid_ts_idxon _hyper_5_11_chunk (cost=0.14..8.15 rows=1 width=41)
208+
Index Cond: (uuid_ts='2000-01-01 00:01:00+00'::timestamp with time zone)
205209
(3 rows)
206210

207211
test=# explain select * from my_table
208-
wherecreated_at>= uuid_v7_to_ts('018c1ecb-d3b7-75b1-add9-62878b5152c7')
209-
order bycreated_atdesclimit10;
212+
whereuuid_ts>= uuid_v7_to_ts('018c1ecb-d3b7-75b1-add9-62878b5152c7')
213+
order byuuid_tsdesclimit10;
210214
QUERY PLAN
211215
-----------------------------------------------------------------------------------------------------------------------------------
212216
Limit (cost=0.29..1.17 rows=10 width=41)
213217
-> Custom Scan (ChunkAppend)on my_table (cost=0.29..11.49 rows=126 width=41)
214-
Order:my_table.created_atDESC
215-
-> Index Scan using_hyper_5_16_chunk_my_table_created_at_idxon _hyper_5_16_chunk (cost=0.29..11.49 rows=126 width=41)
216-
Index Cond: (created_at>='2023-11-30 05:55:23.703+00'::timestamp with time zone)
218+
Order:my_table.uuid_tsDESC
219+
-> Index Scan using_hyper_5_16_chunk_my_table_uuid_ts_idxon _hyper_5_16_chunk (cost=0.29..11.49 rows=126 width=41)
220+
Index Cond: (uuid_ts>='2023-11-30 05:55:23.703+00'::timestamp with time zone)
217221
(5 rows)
218222
```
219223

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp