Skip to content

Instantly share code, notes, and snippets.

explain analyze select * from user_details where to_date(details ->>'dateOfBirth', 'YYYY-MM-DD') = '2000-03-01' limit 50;
QUERY PLAN |
-------------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..750.37 rows=50 width=426) (actual time=0.148..1231.418 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..281389.00 rows=18750 width=426) (actual time=0.147..1231.401 rows=50 loops=1)|
Filter: (to_date((details ->> 'dateOfBirth'::text), 'YYYY-MM-DD'::text) = '2000-03-01'::date) |
Rows Removed by Filter: 2123988 |
Planning Time: 0.063 ms |
Execution Time: 1231.454 ms
explain analyze select * from user_details where details ->> 'alternateContacts' like '%777%' limit 50;
QUERY PLAN |
-----------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..90.67 rows=50 width=426) (actual time=0.594..4.489 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..272014.00 rows=150000 width=426) (actual time=0.592..4.480 rows=50 loops=1)|
Filter: ((details ->> 'alternateContacts'::text) ~~ '%777%'::text) |
Rows Removed by Filter: 4384 |
Planning Time: 0.074 ms |
Execution Time: 4.510 ms
explain analyze select * from user_details where details @> '{"alternateContacts" : ["+6171836370278"]}';
QUERY PLAN |
---------------------------------------------------------------------------------------------------------------------------------|
Gather (cost=1000.00..236670.25 rows=3750 width=426) (actual time=646.851..652.494 rows=1 loops=1) |
Workers Planned: 2 |
Workers Launched: 2 |
-> Parallel Seq Scan on user_details (cost=0.00..235295.25 rows=1562 width=426) (actual time=618.252..618.545 rows=0 loops=3)|
Filter: (details @> '{"alternateContacts": ["+6171836370278"]}'::jsonb) |
explain analyze select * from user_details where details ->> 'alternateContacts' like '%+6171836370278%';
QUERY PLAN |
---------------------------------------------------------------------------------------------------------------------------------|
Gather (cost=1000.00..236670.25 rows=3750 width=426) (actual time=633.497..639.577 rows=1 loops=1) |
Workers Planned: 2 |
Workers Launched: 2 |
-> Parallel Seq Scan on user_details (cost=0.00..235295.25 rows=1562 width=426) (actual time=619.500..619.760 rows=0 loops=3)|
Filter: (details @> '{"alternateContacts": ["+6171836370278"]}'::jsonb) |
explain analyze select * from user_details where details ->> 'alternateContacts' = '+6171836370278';
QUERY PLAN |
---------------------------------------------------------------------------------------------------------------------------------|
Gather (cost=1000.00..242076.50 rows=18750 width=426) (actual time=667.376..672.194 rows=0 loops=1) |
Workers Planned: 2 |
Workers Launched: 2 |
-> Parallel Seq Scan on user_details (cost=0.00..239201.50 rows=7812 width=426) (actual time=631.365..631.365 rows=0 loops=3)|
Filter: ((details ->> 'alternateContacts'::text) = '%+6171836370278%'::text) |
explain analyze select * from user_details where details ->> 'hasDisability' = 'false' limit 50;
QUERY PLAN |
----------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..725.37 rows=50 width=426) (actual time=0.014..0.064 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..272014.00 rows=18750 width=426) (actual time=0.013..0.058 rows=50 loops=1)|
Filter: ((details ->> 'hasDisability'::text) = 'false'::text) |
Rows Removed by Filter: 70 |
Planning Time: 0.062 ms |
Execution Time: 0.079 ms
explain analyze select * from user_details where details ->> 'familyMembers' >= '1' and details ->> 'familyMembers' <= '3' limit 50;
QUERY PLAN |
---------------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..775.37 rows=50 width=426) (actual time=0.019..0.656 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..290764.00 rows=18750 width=426) (actual time=0.018..0.652 rows=50 loops=1) |
Filter: (((details ->> 'familyMembers'::text) >= '1'::text) AND ((details ->> 'familyMembers'::text) <= '3'::text))|
Rows Removed by Filter: 100 |
Planning Time: 0.096 ms |
Execution Time:
explain analyze select * from user_details where jsonb_extract_path_text(details,'familyMembers') :: int = 9 limit 50;
QUERY PLAN |
-----------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..725.37 rows=50 width=426) (actual time=0.033..26.974 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..272014.00 rows=18750 width=426) (actual time=0.032..26.968 rows=50 loops=1)|
Filter: ((details ->> 'familyMembers'::text) = '9'::text) |
Rows Removed by Filter: 73588 |
Planning Time: 0.212 ms |
Execution Time: 26.997 ms
select * from user_details where details ->> 'profession' like '%Farm%' limit 50;
QUERY PLAN |
----------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..453.36 rows=50 width=426) (actual time=0.024..0.169 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..272014.00 rows=30000 width=426) (actual time=0.023..0.165 rows=50 loops=1)|
Filter: ((details ->> 'profession'::text) ~~ '%Farm%'::text) |
Rows Removed by Filter: 216 |
Planning Time: 0.152 ms |
Execution Time: 0.211 ms
explain analyze select * from user_details where details ->> 'profession' = 'Farmer' limit 50;
QUERY PLAN |
----------------------------------------------------------------------------------------------------------------------|
Limit (cost=0.00..725.37 rows=50 width=426) (actual time=0.014..0.247 rows=50 loops=1) |
-> Seq Scan on user_details (cost=0.00..272014.00 rows=18750 width=426) (actual time=0.013..0.241 rows=50 loops=1)|
Filter: ((details ->> 'profession'::text) = 'Farmer'::text) |
Rows Removed by Filter: 276 |
Planning Time: 0.075 ms |
Execution Time: 0.267 ms