I want to extract results from EAV (entity-attribute-value) tables, or more specifically entity-metadata tables (think like wordpress wp_posts
and wp_post
The best way to find out would be to test, off course. The answer may be different depending on the size of the dataset, the number of different meta-keys, their distribution (do all entities have values for all meta-keys? or only for a few of them?), the settings of your database server and possibly many other factors.
If I were to guess, I'd say that the cost of the JOIN
operations in option 2 would be smaller than the cost of GROUP BY
and aggregate functions needed in options 1 and 3.
So, I would expect to find Option 2 faster than 1 and 3.
To measure Option 4, you'll have to consider more factors as the application may be in another server so the loads of the two (db and application) servers and the number of clients that will be requesting these results have to be taken into account.
Sidenote: you need GROUP BY e.ID
in options 1 and 3.