mysql - What is an efficient way to query against an entity-attribute-value model -
I am working with a database like this:
unit field value 1
And I want to ask all the entities with the artist name "some names" which have started but have not ended.
I came up with something like this:
select from start.entity field_values as' start 'INNER field_included as values' end 'Inner Field' contains the values as' Artist 'where (begin .field =' start_date 'and end.field =' end_date 'and artist.field =' artist ') and (STR_TO_DATE (start.value,'% M% D,% Y ') & lt; now () and STR_TO_DATE (end .value,'% M% d,% Y ')> NOW ()) and artist.value = "some artists";
But does not it hurt me as being incredibly efficient, is there a better view on this?
For the sake of clarity you join the section, but in terms of query optimization it is too much of doing this The way.
You might consider writing the query again in this way:
Join SELECT start.entity unit FIND_values as entity.id = start.entity And include start.field = 'start_date' INNER field_values entity.id = end.entity and end.field = 'end_date' INNER JOIN field_values as the artist on the unit .id = artist.entity And artist.field = 'Artists' where STR_TO_DATE (start.value, '% M% d,% Y') & lt; Now () and STR_TO_DATE (end.value, '% M% d,% Y') & gt; Now () and artist.value = "some artists";
You can also make the field even common to save some space (it is assumed that the field is not an enum)
Comments
Post a Comment