the deal is this:
I have a MySQL database that is built in this manner:
There are three tables, one for “objects”:
ID | Type | Name | Description
--------------------------------------------
1 | Restaurant | Joe's Grill | A Great Place
and than a table for metadata about each “object” designed like:
Object ID | Name ID | Description ID
-----------------------------------
1 | 2 | 4
and another table for the strings of the metadata:
ID | String
---------------
1 | Hello
2 | City
3 | London
4 | Paris
so in this case Joe’s Grill restaurant (ID: 1) has a metadata attached to it
(you can see that by the Object ID column of the metadata table)
and the Name ID and Description ID columns correspond to the strings of the metadata strings table.
The problem is that SELECT queries will need multiple JOINs each time,
so I wanted to create a view that will do this automatically,
the thing is I also want indexes for this view because the view will
also get very large.
The question is:
-
I know it’s not possible to create an index for a view? is there an alternative to this?
-
if not, what’s the next best option? maybe there’s another way except a view
to create a table out of a query?
maybe set up a script that will do this? -
if neither of those is possible, is there anything else I can do?
Thank you all in advance, I’ve really been cracking my head over this
for quite some time.
sounds like you want a materialized view.
an alternative is to just generate large but well optimized queries. that might be okay depending upon your requirements…