By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
| version |
|---|
| PostgreSQL 14.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit |
SELECT 1
CREATE TABLE
INSERT 0 1
INSERT 0 299999
ANALYZE
| string_to_array |
|---|
| {xxx,eod,nhoj,oof,rab} |
SELECT 1
| unnest |
|---|
| xxx |
| eod |
| nhoj |
| oof |
| rab |
SELECT 5
| t_field | id | elem | num |
|---|---|---|---|
| bar$foo$john$doe$xxx | 1 | xxx | 1 |
| bar$foo$john$doe$xxx | 1 | eod | 2 |
| bar$foo$john$doe$xxx | 1 | nhoj | 3 |
| bar$foo$john$doe$xxx | 1 | oof | 4 |
| bar$foo$john$doe$xxx | 1 | rab | 5 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 4e9 | 1 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | e0f | 2 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 89ecd | 3 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | a5aae | 4 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 0a0c | 5 |
SELECT 10
| t_field | id | elem | num |
|---|---|---|---|
| bar$foo$john$doe$xxx | 1 | xxx | 1 |
| bar$foo$john$doe$xxx | 1 | eod | 2 |
| bar$foo$john$doe$xxx | 1 | nhoj | 3 |
| bar$foo$john$doe$xxx | 1 | oof | 4 |
| bar$foo$john$doe$xxx | 1 | rab | 5 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 4e9 | 1 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | e0f | 2 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 89ecd | 3 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | a5aae | 4 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 0a0c | 5 |
SELECT 10
| t_field | id | elem | rn |
|---|---|---|---|
| bar$foo$john$doe$xxx | 1 | xxx | 1 |
| bar$foo$john$doe$xxx | 1 | eod | 2 |
| bar$foo$john$doe$xxx | 1 | nhoj | 3 |
| bar$foo$john$doe$xxx | 1 | oof | 4 |
| bar$foo$john$doe$xxx | 1 | rab | 5 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 4e9 | 1 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | e0f | 2 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 89ecd | 3 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | a5aae | 4 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 0a0c | 5 |
SELECT 10
| t_field | result |
|---|---|
| bar$foo$john$doe$xxx | bar$foo$john$doe-xxx |
| c0a0$eaa5a$dce98$f0e$9e4 | c0a0$eaa5a$dce98$f0e-9e4 |
SELECT 2
| QUERY PLAN |
|---|
| GroupAggregate (cost=8.87..2600529.87 rows=300000 width=36) (actual rows=300000 loops=1) |
| Group Key: t.id |
| -> Nested Loop (cost=8.87..56529.87 rows=900000 width=36) (actual rows=1200000 loops=1) |
| -> Index Only Scan using test_pkey on test t (cost=0.42..10021.42 rows=300000 width=4) (actual rows=300000 loops=1) |
| Heap Fetches: 300000 |
| -> Function Scan on unnest x (cost=8.45..8.57 rows=3 width=32) (actual rows=4 loops=300000) |
| Filter: (num > 1) |
| Rows Removed by Filter: 1 |
| SubPlan 2 |
| -> Index Scan using test_pkey on test test_1 (cost=0.42..8.44 rows=1 width=24) (actual rows=1 loops=300000) |
| Index Cond: (id = t.id) |
| SubPlan 1 |
| -> Index Scan using test_pkey on test (cost=0.42..8.44 rows=1 width=32) (actual rows=1 loops=300000) |
| Index Cond: (id = t.id) |
| Planning Time: 0.155 ms |
| Execution Time: 4047.734 ms |
EXPLAIN
| f | result |
|---|---|
| bar$foo$john$doe$xxx | bar$foo$john$doe-xxx |
| c0a0$eaa5a$dce98$f0e$9e4 | c0a0$eaa5a$dce98$f0e-9e4 |
SELECT 2
| QUERY PLAN |
|---|
| GroupAggregate (cost=8.87..2600529.87 rows=300000 width=60) (actual rows=300000 loops=1) |
| Group Key: t.id |
| -> Nested Loop (cost=8.87..56529.87 rows=900000 width=60) (actual rows=1200000 loops=1) |
| -> Index Scan using test_pkey on test t (cost=0.42..10021.42 rows=300000 width=28) (actual rows=300000 loops=1) |
| -> Function Scan on unnest x (cost=8.45..8.57 rows=3 width=32) (actual rows=4 loops=300000) |
| Filter: (num > 1) |
| Rows Removed by Filter: 1 |
| SubPlan 2 |
| -> Index Scan using test_pkey on test test_1 (cost=0.42..8.44 rows=1 width=24) (actual rows=1 loops=300000) |
| Index Cond: (id = t.id) |
| SubPlan 1 |
| -> Index Scan using test_pkey on test (cost=0.42..8.44 rows=1 width=32) (actual rows=1 loops=300000) |
| Index Cond: (id = t.id) |
| Planning Time: 0.150 ms |
| Execution Time: 4011.771 ms |
EXPLAIN
| t_field | id | elem | rn |
|---|---|---|---|
| bar$foo$john$doe$xxx | 1 | xxx | 1 |
| bar$foo$john$doe$xxx | 1 | eod | 2 |
| bar$foo$john$doe$xxx | 1 | nhoj | 3 |
| bar$foo$john$doe$xxx | 1 | oof | 4 |
| bar$foo$john$doe$xxx | 1 | rab | 5 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 4e9 | 1 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | e0f | 2 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 89ecd | 3 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | a5aae | 4 |
| c0a0$eaa5a$dce98$f0e$9e4 | 2 | 0a0c | 5 |
SELECT 10
| f | result |
|---|---|
| bar$foo$john$doe$xxx | bar$foo$john$doe-xxx |
| c0a0$eaa5a$dce98$f0e$9e4 | c0a0$eaa5a$dce98$f0e-9e4 |
SELECT 2
| QUERY PLAN |
|---|
| GroupAggregate (cost=9.03..8670029.87 rows=1000000 width=60) (actual rows=300000 loops=1) |
| Group Key: tab.id, tab.f |
| -> Incremental Sort (cost=9.03..197529.87 rows=1000000 width=60) (actual rows=1200000 loops=1) |
| Sort Key: tab.id, tab.f |
| Presorted Key: tab.id |
| Full-sort Groups: 37500 Sort Method: quicksort Average Memory: 27kB Peak Memory: 27kB |
| -> Subquery Scan on tab (cost=8.87..152529.87 rows=1000000 width=60) (actual rows=1200000 loops=1) |
| Filter: (tab.rn > 1) |
| Rows Removed by Filter: 300000 |
| -> WindowAgg (cost=8.87..115029.87 rows=3000000 width=68) (actual rows=1500000 loops=1) |
| -> Nested Loop (cost=8.87..70029.87 rows=3000000 width=60) (actual rows=1500000 loops=1) |
| -> Index Scan using test_pkey on test t (cost=0.42..10021.42 rows=300000 width=28) (actual rows=300000 loops=1) |
| -> Function Scan on unnest s (cost=8.45..8.55 rows=10 width=32) (actual rows=5 loops=300000) |
| SubPlan 2 |
| -> Index Scan using test_pkey on test test_1 (cost=0.42..8.44 rows=1 width=24) (actual rows=1 loops=300000) |
| Index Cond: (id = t.id) |
| SubPlan 1 |
| -> Index Scan using test_pkey on test (cost=0.42..8.44 rows=1 width=32) (actual rows=1 loops=300000) |
| Index Cond: (id = tab.id) |
| Planning Time: 0.161 ms |
| Execution Time: 5003.977 ms |
EXPLAIN