重複する行を含むc_regsテーブルがあります。私は、form_number列とproperty_name列に索引を作成しました。残念なことに、このクエリは、特にt10とt11の結合を追加することで、o-o-oを完了するのに時間がかかります。それを最適化する方法はありますか?ありがとう。MySQL自己結合クエリを最適化する
select
ifnull(x.form_datetime,'') reg_date,
ifnull(x.property_value,'') amg_id,
x.form_number,
x.form_name,
x.form_version,
ifnull(t1.property_value,'') first_name,
ifnull(t2.property_value,'') last_name,
ifnull(t3.property_value,'') address,
ifnull(t4.property_value,'') address_2,
ifnull(t5.property_value,'') city,
ifnull(t6.property_value,'') state_code,
ifnull(t7.property_value,'') zip,
ifnull(t8.property_value,'') phone,
ifnull(t9.property_value,'') email,
ifnull(t10.property_value,'') registrant_type,
t11.property_value auth_type_code
from
(select distinct form_datetime, form_number, form_name, form_version, property_value from c_regs where property_name = 'field.frm_personID') as x
inner join (select distinct * from c_regs) as t1 on t1.form_number = x.form_number and t1.property_name = 'field.frm_firstName'
inner join (select distinct * from c_regs) as t2 on t2.form_number = x.form_number and t2.property_name = 'field.frm_lastName'
inner join (select distinct * from c_regs) as t3 on t3.form_number = x.form_number and t3.property_name = 'field.frm_address'
left join (select distinct * from c_regs) as t4 on t4.form_number = x.form_number and t4.property_name = 'field.frm_address2'
inner join (select distinct * from c_regs) as t5 on t5.form_number = x.form_number and t5.property_name = 'field.frm_city'
inner join (select distinct * from c_regs) as t6 on t6.form_number = x.form_number and t6.property_name = 'field.frm_state'
inner join (select distinct * from c_regs) as t7 on t7.form_number = x.form_number and t7.property_name = 'field.frm_zip'
inner join (select distinct * from c_regs) as t8 on t8.form_number = x.form_number and t8.property_name = 'field.frm_phone'
inner join (select distinct * from c_regs) as t9 on t9.form_number = x.form_number and t9.property_name = 'field.frm_emailAddress'
left join (select distinct * from c_regs) as t10 on t10.form_number = x.form_number and t10.property_name = 'field.frm_youAre'
inner join (select distinct * from c_regs) as t11 on t11.form_number = x.form_number and t11.property_name = 'field.frm_authType'
;
ニース! 35分から0.01秒まで。 :)私は次にそれを勉強するつもりなので、何が起こっているのか正確に理解しています。手伝ってくれてどうもありがとう! – demisx
喜んで助けてください! Stack Overflowでは、あなたを助けてくれた回答をupvoteまたは受け入れることが慣例であることに注意してください。 :-) –
私の経験では、このような種類のクエリ(読みやすい)は、選択肢よりも部分的に遅いです。 – Strawberry