add remove split language show hidden hide
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
setseed
SELECT 1
CREATE TABLE
INSERT 0 300000
CREATE INDEX
CREATE INDEX
CREATE INDEX
VACUUM
QUERY PLAN
Limit (cost=22.80..103.17 rows=10 width=50) (actual time=24.485..47.409 rows=634 loops=1)
  Output: products.id, products.created_at, products.name
  CTE cte
    -> ProjectSet (cost=22.50..22.57 rows=10 width=32) (actual time=12.157..14.241 rows=20000 loops=1)
          Output: unnest((array_agg(("left"((random())::text, 9)))))
          -> Aggregate (cost=22.50..22.52 rows=1 width=32) (actual time=12.137..12.138 rows=1 loops=1)
                Output: array_agg(("left"((random())::text, 9)))
                -> Function Scan on pg_catalog.generate_series (cost=0.00..20.00 rows=1000 width=32) (actual time=3.152..10.016 rows=20000 loops=1)
                      Output: "left"((random())::text, 9)
                      Function Call: generate_series('1'::numeric, '20000'::numeric)
  -> Nested Loop (cost=0.23..80.60 rows=10 width=50) (actual time=24.484..47.333 rows=634 loops=1)
        Output: products.id, products.created_at, products.name
        -> HashAggregate (cost=0.23..0.33 rows=10 width=32) (actual time=24.343..28.019 rows=19976 loops=1)
              Output: cte.search_for_this
              Group Key: cte.search_for_this
              Batches: 1 Memory Usage: 1833kB
              -> CTE Scan on cte (cost=0.00..0.20 rows=10 width=32) (actual time=12.161..18.573 rows=20000 loops=1)
                    Output: cte.search_for_this
        -> Index Scan using product_id_idx2 on public.products (cost=0.00..8.02 rows=1 width=50) (actual time=0.001..0.001 rows=0 loops=19976)
              Output: products.id, products.created_at, products.name
              Index Cond: (products.id = cte.search_for_this)
              Rows Removed by Index Recheck: 0
Planning Time: 0.934 ms
Execution Time: 47.807 ms
EXPLAIN