I have created index on userID column, data type of this column is character varying(1000)
Case 1. when I am putting record 12 or less than 12 inside IN query
Query
<code>explain SELECT * FROM users_8116 WHERE "userID" in ('4', '9678', '19036', '24930', '31669', '43604', '46754', '51422', '63743', '69826', '84860', '98225')
</code>
<code>explain SELECT * FROM users_8116 WHERE "userID" in ('4', '9678', '19036', '24930', '31669', '43604', '46754', '51422', '63743', '69826', '84860', '98225')
</code>
explain SELECT * FROM users_8116 WHERE "userID" in ('4', '9678', '19036', '24930', '31669', '43604', '46754', '51422', '63743', '69826', '84860', '98225')
QUERY PLAN
<code>"Gather (cost=53214.43..947715.53 rows=554610 width=3716)"
" Workers Planned: 2"
" -> Parallel Bitmap Heap Scan on users_8116 (cost=52214.43..891254.53 rows=231088 width=3716)"
" Recheck Cond: ((""userID"")::text = ANY ('{4,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
" -> Bitmap Index Scan on user_userid_8116_index (cost=0.00..52075.75 rows=554610 width=0)"
" Index Cond: ((""userID"")::text = ANY ('{4,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
</code>
<code>"Gather (cost=53214.43..947715.53 rows=554610 width=3716)"
" Workers Planned: 2"
" -> Parallel Bitmap Heap Scan on users_8116 (cost=52214.43..891254.53 rows=231088 width=3716)"
" Recheck Cond: ((""userID"")::text = ANY ('{4,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
" -> Bitmap Index Scan on user_userid_8116_index (cost=0.00..52075.75 rows=554610 width=0)"
" Index Cond: ((""userID"")::text = ANY ('{4,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
</code>
"Gather (cost=53214.43..947715.53 rows=554610 width=3716)"
" Workers Planned: 2"
" -> Parallel Bitmap Heap Scan on users_8116 (cost=52214.43..891254.53 rows=231088 width=3716)"
" Recheck Cond: ((""userID"")::text = ANY ('{4,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
" -> Bitmap Index Scan on user_userid_8116_index (cost=0.00..52075.75 rows=554610 width=0)"
" Index Cond: ((""userID"")::text = ANY ('{4,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
Case 2. when I am putting record more than 12 inside IN query
Query
<code>explain SELECT * FROM users_8116 WHERE "userID" in ('4', '41', '9678', '19036', '24930', '31669', '43604', '46754', '51422', '63743', '69826', '84860', '98225')
</code>
<code>explain SELECT * FROM users_8116 WHERE "userID" in ('4', '41', '9678', '19036', '24930', '31669', '43604', '46754', '51422', '63743', '69826', '84860', '98225')
</code>
explain SELECT * FROM users_8116 WHERE "userID" in ('4', '41', '9678', '19036', '24930', '31669', '43604', '46754', '51422', '63743', '69826', '84860', '98225')
QUERY PLAN
<code>"Gather (cost=1000.03..957253.58 rows=600827 width=3716)"
" Workers Planned: 2"
" -> Parallel Seq Scan on users_8116 (cost=0.03..896170.88 rows=250345 width=3716)"
" Filter: ((""userID"")::text = ANY ('{4,41,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
</code>
<code>"Gather (cost=1000.03..957253.58 rows=600827 width=3716)"
" Workers Planned: 2"
" -> Parallel Seq Scan on users_8116 (cost=0.03..896170.88 rows=250345 width=3716)"
" Filter: ((""userID"")::text = ANY ('{4,41,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
</code>
"Gather (cost=1000.03..957253.58 rows=600827 width=3716)"
" Workers Planned: 2"
" -> Parallel Seq Scan on users_8116 (cost=0.03..896170.88 rows=250345 width=3716)"
" Filter: ((""userID"")::text = ANY ('{4,41,9678,19036,24930,31669,43604,46754,51422,63743,69826,84860,98225}'::text[]))"
Index definition
<code>CREATE INDEX user_userid_8116_index
ON public.users_8116 USING btree
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default;
</code>
<code>CREATE INDEX user_userid_8116_index
ON public.users_8116 USING btree
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default;
</code>
CREATE INDEX user_userid_8116_index
ON public.users_8116 USING btree
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default;
I do not want to do query with sequential scan, index should be used