I have a table in postgresql11 which has a userId
as a column. And it is not primary key in the table.
I need to perform below update statement on the table.
update entity set name='xxxx' where userId = 'yyy
.
The userId
is in the where
condition but I don't know whether I should create an index for userId
. Will it improve performance? If yes, how can I specify index in the update
statement?
-
I don't know whether I should create an index You may, but not must.Akina– Akina2021年02月09日 12:08:53 +00:00Commented Feb 9, 2021 at 12:08
1 Answer 1
Indexes are meant to improve performance of predicates used in WHERE
, JOIN
, and HAVING
clauses for any type of query. So yes having an index on userId
theoretically can improve performance of your UPDATE
example query.
After you create the index you don't need to specify it in your query, PostgreSQL will automatically use it if its engine thinks it'll help the query performance.