Definition of the employees
table is as follow
Table "public.employees"
Column | Type | Collation | Nullable | Default
---------------+-------------------------+-----------+----------+---------
employee_id | integer | | not null |
first_name | character varying(1000) | | not null |
last_name | character varying(1000) | | not null |
date_of_birth | date | | not null |
phone_number | character varying(1000) | | not null |
subsidiary_id | integer | | |
Indexes:
"employee_pk" UNIQUE, btree (employee_id, subsidiary_id)
Content of the employees
table is as follow
employee_id | first_name | last_name | date_of_birth | phone_number | subsidiary_id
-------------+------------+-----------+---------------+--------------+---------------
120 | Ajay | Yadav | 2019-09-04 | 1232323 | 1
129 | Rohit | Gupta | 2019-09-04 | 1232323 | 1
123 | Vikash | Sharma | 2019-09-04 | 1232323 | 2
130 | Jay | Sharma | 2019-09-05 | 1232323 | 3
131 | Jay | Sharma | 2019-09-05 | 1232323 | 2
134 | Jay | Sharma | 2019-09-05 | 1232323 | 3
(6 rows)
Checked the execution plan for the select query with employee id as the condition.
QUERY PLAN
------------------------------------------------------------
Seq Scan on employees (cost=0.00..1.04 rows=1 width=1560)
Filter: (employee_id = 123)
(2 rows)
The execution plan is showing that the query engine hasn't used the index and did a table scan operation.
The index contains employee Id as the first parameter then why database haven't used the index ?