php - Does adding an index on the column you are selecting speed up the query? -


i have common setup, have table of tags , record pairs. querying slow adding index column of tag querying helps speed up.

 tag  | site 123  | 456 789  | 101 

my question whether beneficial add index on both these columns 1 index. never selected site, there benefit doing this? cannot guarantee each pairing unique without making changes if did performance?

a typical query might this:

 select site, tag sitetags tag ='123' or tag = '789' 

if search tag need index tag column.

adding column index when not used, introduce unneeded overhead when insert or update record , consume more storages.

but composite index (tag, site) may give additional optimization mysql need read index satify query (explain marks optimization using index).

if operation read rather write, using composite index may not bad idea.

it better if tag column has high cardinality, meaning there high chance values different between each rows.

but suggest consult explain output first.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -