clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2335547 fiddles created (27403 in the last week).

set enable_bitmapscan=false
 hidden batch(es)


create table demo (id bigint, username text)
 hidden batch(es)


insert into demo select n,'Number'||to_hex(n) from generate_series(1,1000) n
1000 rows affected
 hidden batch(es)


vacuum demo
 hidden batch(es)


select * from demo where username='Number42'
id username
66 Number42
 hidden batch(es)


explain analyze select * from demo where upper(username)='NUMBER42'
QUERY PLAN
Seq Scan on demo (cost=0.00..22.00 rows=5 width=40) (actual time=0.097..0.444 rows=1 loops=1)
Filter: (upper(username) = 'NUMBER42'::text)
Rows Removed by Filter: 999
Planning Time: 0.025 ms
Execution Time: 0.454 ms
 hidden batch(es)


explain analyze select upper(username) from demo where upper(username)='NUMBER42'
QUERY PLAN
Seq Scan on demo (cost=0.00..22.01 rows=5 width=32) (actual time=0.033..0.351 rows=1 loops=1)
Filter: (upper(username) = 'NUMBER42'::text)
Rows Removed by Filter: 999
Planning Time: 0.024 ms
Execution Time: 0.361 ms
 hidden batch(es)


create index demo_upper on demo( (upper(username)) )
 hidden batch(es)


explain analyze select upper(username) from demo where upper(username)='NUMBER42'
QUERY PLAN
Index Scan using demo_upper on demo (cost=0.28..20.38 rows=5 width=32) (actual time=0.043..0.045 rows=1 loops=1)
Index Cond: (upper(username) = 'NUMBER42'::text)
Planning Time: 0.272 ms
Execution Time: 0.067 ms
 hidden batch(es)


create index demo_upper_covering on demo( (upper(username))) include (username )
 hidden batch(es)


explain analyze select upper(username) from demo where upper(username)='NUMBER42'
QUERY PLAN
Index Only Scan using demo_upper_covering on demo (cost=0.28..4.38 rows=5 width=32) (actual time=0.044..0.046 rows=1 loops=1)
Index Cond: ((upper(username)) = 'NUMBER42'::text)
Heap Fetches: 0
Planning Time: 0.206 ms
Execution Time: 0.066 ms
 hidden batch(es)


alter table demo add column upper_username text generated always as (upper(username)) stored
 hidden batch(es)


create index demo_upper_stored on demo( upper_username )
 hidden batch(es)


vacuum demo
 hidden batch(es)


explain analyze select upper_username from demo where upper_username='NUMBER42'
QUERY PLAN
Index Only Scan using demo_upper_stored on demo (cost=0.28..4.36 rows=5 width=32) (actual time=0.046..0.047 rows=1 loops=1)
Index Cond: (upper_username = 'NUMBER42'::text)
Heap Fetches: 0
Planning Time: 0.123 ms
Execution Time: 0.066 ms
 hidden batch(es)