के साथ प्रदर्शन में सुधार करें मेरे पास एक MySQL क्वेरी है जिसमें 5 या 6 बाएं जॉइन हैं। जैसा कि उम्मीद है, यह बहुत धीमी है। यह ध्यान में रखते हुए कि मैं केवल 100 परिणामों की उम्मीद कर रहा हूं, क्या यह मेरे लिए बहुत से अलग SQL क्वेरी पूछने और मैन्युअल रूप से उन्हें सिलाई करने के लिए अधिक समझ में आ सकता है। मुझे लगता है कि कई बाएं जुड़ने के साथ बनाई गई विशाल तालिका के कारण इसमें काफी समय लग रहा है। क्या वह सही है?LEFT JOIN
मैं इसे रेल 3 में कर रहा हूं। मुझे पता है कि सक्रिय रिकॉर्ड बनाना महंगा है, लेकिन मुझे लगता है कि यह इतने सारे बाएं जॉइन होने से तेज़ हो सकता है। मैं हुड के नीचे डेटाबेस कैसे काम करता है इस बारे में बहुत कम जानता हूं। वास्तव में किसी भी अंतर्दृष्टि की सराहना करेंगे।
संपादित करें: यहाँ वास्तविक क्वेरी और तालिका स्कीमा
क्वेरी है
people
का चयन करें *people
से छोड़ दियाperson_organization_relationships
शामिल हों परperson_organization_relationships
.person_id =people
.id औरperson_organization_relationships
।। stop_person है NULL LEFT JOINperson_redirect_relationships
AS r_from_others पर r_from_others.parent_id =people
.id और r_from_others.stop_person है शून्य बायाँ शामिल होंperson_redirect_relationships
r_to_others के रूप में पर r_to_others.child_id =people
.id और r_to_others.stop_person शून्य है बायाँ शामिल होंperson_organization_relationships
के रूप में r_p_check पर r_p_check.person_id = r_from_others। child_id और r_p_check.stop_person शून्य बायाँ शामिल होंorganization_redirect_relationships
के रूप में r_o_check पर r_o_check.child_id =person_organization_relationships
.organization_id और r_o_check.stop_organization शून्य बायाँ शामिल होंperson_organization_relationships
के रूप में rr_p_check पर rr_p_check.person_id = r_from_others.child_i है डी और rr_p_check.stop_person शून्य बायाँ शामिल होंorganization_redirect_relationships
पर rr_p_check.organization_id = rr_o_check.child_id और rr_o_check.stop_organization शून्य है जहां (((person_organization_relationships
.organization_id = 1 या r_o_check.parent_id = 1) और r_to_others के रूप में rr_o_check है: .parent_id शून्य) या (r_p_check.organization_id = 1 या rr_o_check.parent_id = 1)) ग्रुप द्वाराcreate_table "people", :force => true do |t| t.datetime "created_at" t.datetime "updated_at" t.boolean "delta", :default => true, :null => false end create_table "person_organization_relationships", :force => true do |t| t.integer "person_id" t.integer "organization_id" t.integer "start_person" t.integer "stop_person" t.datetime "created_at" t.datetime "updated_at" end add_index "person_organization_relationships", ["organization_id"], :name => "index_person_organization_relationships_on_organization_id" add_index "person_organization_relationships", ["person_id"], :name => "index_person_organization_relationships_on_person_id" add_index "person_organization_relationships", ["start_person"], :name => "index_person_organization_relationships_on_start_person" add_index "person_organization_relationships", ["stop_person"], :name => "index_person_organization_relationships_on_stop_person" create_table "person_redirect_relationships", :force => true do |t| t.integer "parent_id" t.integer "child_id" t.integer "start_person" t.integer "stop_person" t.datetime "created_at" t.datetime "updated_at" end add_index "person_redirect_relationships", ["child_id"], :name => "index_person_redirect_relationships_on_child_id" add_index "person_redirect_relationships", ["parent_id"], :name => "index_person_redirect_relationships_on_parent_id" add_index "person_redirect_relationships", ["start_person"], :name => "index_person_redirect_relationships_on_start_person" add_index "person_redirect_relationships", ["stop_person"], :name => "index_person_redirect_relationships_on_stop_person" create_table "organization_redirect_relationships", :force => true do |t| t.integer "parent_id" t.integer "child_id" t.integer "start_organization" t.integer "stop_organization" t.datetime "created_at" t.datetime "updated_at" end add_index "organization_redirect_relationships", ["child_id"], :name => "index_organization_redirect_relationships_on_child_id" add_index "organization_redirect_relationships", ["parent_id"], :name => "index_organization_redirect_relationships_on_parent_id" add_index "organization_redirect_relationships", ["start_organization"], :name => "index_organization_redirect_relationships_on_start_organization" add_index "organization_redirect_relationships", ["stop_organization"], :name => "index_organization_redirect_relationships_on_stop_organization"
people
.id
तालिका स्कीमा है
इस प्रश्न से कोई परिणाम नहीं मिला।
+ ---- + ------------- + ------------------------ ----------- + -------- + ----------------------------- -------------------------------------------------- --------------------------------------- + ---------- --------------------------------------------- + ---- ----- + -------------------------------------------- ---------------------------- + ------ + -------------- ------------------- + | आईडी | select_type | टेबल | टाइप करें | संभव_keys
| कुंजी | key_len | रेफरी
| पंक्तियां | अतिरिक्त | + ---- + ------------- + ----------------------------- ------ + -------- + ---------------------------------- -------------------------------------------------- ---------------------------------- + --------------- ---------------------------------------- + --------- + ------------------------------------------------- ----------------------- + ------ + ------------------- -------------- + | 1 | सरल | person_details | सभी | index_person_details_on_current_p_id
| नल | नल | NULL
| 4 9 38 | अस्थायी का उपयोग करना; Filesort का उपयोग करना | | 1 | सरल | लोग | eq_ref | प्राथमिक
| प्राथमिक | 4 | knolcano_development.person_details.current_p_id
| 1 | | | 1 | सरल | person_organization_relationships | रेफरी | index_person_organization_relationships_on_person_id, index_person_organization_relationships_on_stop_person | index_person_organization_relationships_on_person_id | 5 | knolcano_development.person_details.current_p_id
| 1 | | | 1 | सरल | r_from_others | रेफरी | index_person_redirect_relationships_on_parent_id, index_person_redirect_relationships_on_stop_person | index_person_redirect_relationships_on_stop_person | 5 | कॉन्स
| 3 | | | 1 | सरल | r_to_others | रेफरी | index_person_redirect_relationships_on_child_id, index_person_redirect_relationships_on_stop_person | index_person_redirect_relationships_on_child_id | 5 | knolcano_development.people.id
| 2 | | | 1 | सरल | r_p_check | रेफरी | index_person_organization_relationships_on_person_id, index_person_organization_relationships_on_stop_person | index_person_organization_relationships_on_person_id | 5 | knolcano_development.r_from_others.child_id
| 1 | | | 1 | सरल | r_o_check | रेफरी | index_organization_redirect_relationships_on_child_id, index_organization_redirect_relationships_on_stop_organization | index_organization_redirect_relationships_on_child_id | 5 | knolcano_development.person_organization_relationships.organization_id | 1 | | | 1 | सरल | rr_p_check | रेफरी | index_person_organization_relationships_on_person_id, index_person_organization_relationships_on_stop_person | index_person_organization_relationships_on_person_id | 5 | knolcano_development.r_from_others.child_id
| 1 | | | 1 | सरल | rr_o_check | रेफरी | index_organization_redirect_relationships_on_child_id, index_organization_redirect_relationships_on_stop_organization | index_organization_redirect_relationships_on_child_id | 5 | knolcano_development.rr_p_check।organization_id
| 1 | कहां उपयोग कर रहा है | + ---- + ------------- + ----------------------------- ------ + -------- + ---------------------------------- -------------------------------------------------- ---------------------------------- + --------------- ---------------------------------------- + --------- + ------------------------------------------------- ----------------------- + ------ + ------------------- -------------- + सेट में 9 पंक्तियां (0.00 सेकंड)
लेकिन जब मैंने क्वेरी चलाई तो यह 0.14 सेकंड लिया। क्या यह एक लंबी अवधि है? मैं यह पता लगाने की कोशिश कर रहा हूं कि क्या मेमकैच को लागू करने से पहले मेरे पास अच्छे प्रश्न हैं।
वास्तविक क्वेरी और EXPLAIN आउटपुट जानकारी के सहायक बिट्स होंगे। –
मैं @JoeStefanelli से सहमत हूं। हमें 'EXPLAIN' का परिणाम + परिणाम दिखाएं। – Tadeck