How to optimize this complicated EAV MYSQL query?

后端 未结 1 1997
暗喜
暗喜 2021-01-06 19:38

Is it possible to optimize this query I have written

I\'ve created a sort of dynamic virtual database to give my users the ability to add custom fields without affec

相关标签:
1条回答
  • 2021-01-06 20:10

    Actually, Chibuzo is right. Start by deleting it :-)) But before, play with it a little, it's a good brain excercise, like chess or something :-)

    select 
        case_id,
        d_status.data_field_value as case_status,
        d_client1_name.forename_company as client1_forename_company
    from db_cases 
            join db_data as d_status 
                on d_status.data_case_id = case_id 
                   AND d_status.data_field_name = 'casestatus'
            join db_data as d_client1
                on d_client1.data_case_id = case_id 
                   AND d_client1.data_field_name = 'client1'
            join db_names as d_client1_name
                on d_client1_name.name_id = d_client1.data_field_value
    

    I would expect these direct joins without subqueries to be much more efficient, though you'll have to test it - there are often surprises in optimizations.

    0 讨论(0)
提交回复
热议问题