mysql - Database: Sorting on non-indexed column -


does creating index on column there in sort order improves performance? need know mysql, postgresql , oracle database.

e.g query:

select * article_comments article_id = 245 order date_created desc limit 30; 

in article_comments table, article_id indexed field, date_created not. if create index on date_created, improve performance. table size around 5-7 million rows.

does creating index on column there in sort order improves performance?

a general answer is: depends on many factors, esspecialy on conditions used in clause.

in case of query index on date_created column doesn't eliminate sort operation due where article_id = 245 clause.

in case need create multicolum index in order skip sorting:

create index somename on article_comments(article_id, date_created desc)


Comments

Popular posts from this blog

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -