0

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?

asked Feb 9, 2021 at 11:56
1
  • I don't know whether I should create an index You may, but not must. Commented Feb 9, 2021 at 12:08

1 Answer 1

4

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.

answered Feb 9, 2021 at 12:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.