I am developing a Wordpress store using the ACF plugin (custom fields). All the parameters of the goods are stored in his meta. accordingly, when filtering in the catalog, I have to do a JOIN table with meta data many times to select all the necessary parameters. The menu in the catalog is dynamic and is compiled depending on what parameters the product has.
Help optimize queries to the database generating the menu, now they look like this:
SELECT vozrat_koshek.post_id,vozrat_koshek.meta_value FROM wp_posts t1 JOIN wp_term_relationships ON wp_term_relationships.object_id=t1.ID JOIN wp_postmeta as vozrat_koshek ON vozrat_koshek.post_id=t1.ID LEFT JOIN wp_postmeta as brend ON brend.post_id = t1.ID AND brend.meta_key='ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»Ρ' AND (brend.meta_value='137' ) LEFT JOIN wp_postmeta as klass_korma ON klass_korma.post_id = brend.post_id AND klass_korma.meta_key='ΠΊΠ»Π°ΡΡ_ΠΊΠΎΡΠΌΠ°' AND (klass_korma.meta_value='premium' ) JOIN wp_postmeta as osobye_potrebnosti ON osobye_potrebnosti.post_id = klass_korma.post_id AND osobye_potrebnosti.meta_key='ΠΎΡΠΎΠ±ΡΠ΅_ΠΏΠΎΡΡΠ΅Π±Π½ΠΎΡΡΠΈ_ΠΊΠ΄ΠΊ' AND (osobye_potrebnosti.meta_value like '%%s:8:\"kastraty\";%%' ) WHERE vozrat_koshek.meta_key='Π²ΠΎΠ·ΡΠ°Ρ_ΠΊΠΎΡΠ΅ΠΊ' and wp_term_relationships.term_taxonomy_id=%d AND brend.meta_key='ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»Ρ' AND (brend.meta_value='137' ) AND klass_korma.meta_key='ΠΊΠ»Π°ΡΡ_ΠΊΠΎΡΠΌΠ°' AND (klass_korma.meta_value='premium' ) and t1.post_status='publish'
explain ΡΠ΅ΠΊΡΡ-Π²Π°ΡΠ΅Π³ΠΎ-Π·Π°ΠΏΡΠΎΡΠ°. You can edit the question by clicking edit below the question text. - aleksandr barakin