HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Can I index all columns of a table in MySQL safely?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cancolumnsallsafelymysqlindextable

Problem

I have one table with 4 columns. One is primary key and other three columns are references to columns of other tables. I am using join on these four tables for a search filter. These joins are taking time.

So I was thinking to have indexes on columns because I read that I should create indexes on columns of join conditions. My question is will there be problem if all columns of the table are indexed? Is there any other way to decrease time complexity of these search filters.

More Hint:

  • Table1(main search)-1000 million entries primary_key fk1 fk2 fk3



  • Table2-800 million entries pk1 ..(8-9 columns)



  • Table3-700 million entries pk2 ..(10-12 columns)



  • Table2-850 million entries pk3 ..(7-8 columns)



I am using MyISAM engine.

Solution

Indexing all columns (index on each column) may or may not improve overall performance. That depends index selectivity. Consider creating covering index for your typical query. For instance, if you usually join all 3 tables, the query will mostly benefit on composite index (f1,f2,f3) . Also, if combination of these 3 fields is unique, you can define primary key on f1,f2,f3, so you don't need surrogate PK (assuming there are no other fields on this table)

Context

StackExchange Database Administrators Q#11040, answer score: 3

Revisions (0)

No revisions yet.