Using PostgreSQL-13, I need advice about key index. I have a table named "employee" and I manage my DB using DBeaver Community Edition (latest).
Fieldname Type
---------- ----
pid bigint - nextval('employee_pid_seq'::regclass) --
Primary Key
company_id varchar(10)
employee_id varchar(10)
employee_name varchar(50)
I'm learning to fine-tune this simple table. company_id and employee_id is a unique index.
When running:
select * from employee order by company_id
... to enhance the performance, do I also need to have company_id as non-unique index?
UNIQUE (company_id, employee_id)will be used. – Akina Dec 27 '22 at 08:45idas VARCHAR is not good idea. Use numeric datatype (INT for example) instead. – Akina Dec 27 '22 at 08:45identitycolumns (generated always as identity) are recommended for auto-generated primary key values.company_idshould probably be a foreign key. Not sure why you have aemployee_id(which sounds like another foreign key column) and anemployee_name. If employee_id is a foreign key the name should be stored in the referenced table. – Dec 27 '22 at 08:46