Indexing views in MySQL

0
I have a view in my MySQL database, I would like to know if it is possible to index the fields that are contained in it, since I have a group by in it that is consuming a lot, and an index would solve this problem or at least help.

Is there any way to do this index in view in MySQL?

    
asked by anonymous 12.07.2016 / 15:49

2 answers

4

You can not do anything specific like that. If the view is not meeting the performance requirements it has three outputs:

  • Do not use view , access the data directly from the tables, you may find that the problem was not even in view and you have to fix the problem that was below.
  • Create indexes that help your searches to be efficient on the physical table, after all that is what matters in fact, indexes are optimizations to access the actual data, not logical data that is the view function. view will benefit if the physical table benefits.
  • Create an auxiliary table with the data you would get from the view (its existence even facilitates this, it is a simple insert/select ) and index it. I know this is not ideal, but it is still an alternative.
12.07.2016 / 15:57
1

To use Indexes in View simply update MySQL to version greater than or equal to 5.6.3, from this version MySQL uses the index derived from the physical table.

    
19.10.2018 / 14:27