- मुझे डेटाबेस में कंपोजिट इंडेक्स का उपयोग कब करना चाहिए?
- एक समग्र सूचकांक का उपयोग करके प्रदर्शन में सुधार क्या हैं)?
- मुझे एक समग्र सूचकांक का उपयोग क्यों करना चाहिए?
उदाहरण के लिए, मेरे पास एक homes
तालिका है:
CREATE TABLE IF NOT EXISTS `homes` (
`home_id` int(10) unsigned NOT NULL auto_increment,
`sqft` smallint(5) unsigned NOT NULL,
`year_built` smallint(5) unsigned NOT NULL,
`geolat` decimal(10,6) default NULL,
`geolng` decimal(10,6) default NULL,
PRIMARY KEY (`home_id`),
KEY `geolat` (`geolat`),
KEY `geolng` (`geolng`),
) ENGINE=InnoDB ;
क्या यह मेरे लिए समझ में आता है कि दोनों के लिए एक समग्र सूचकांक का उपयोग करें , geolat
और geolng
:
मैं प्रतिस्थापित करता हूं:
KEY `geolat` (`geolat`),
KEY `geolng` (`geolng`),
साथ में:
KEY `geolat_geolng` (`geolat`, `geolng`)
यदि ऐसा है तो:
- क्यों?
- एक समग्र सूचकांक का उपयोग करके प्रदर्शन में सुधार क्या है)?
अपडेट करें:
चूंकि कई लोगों ने कहा है कि यह मेरे द्वारा किए जाने वाले प्रश्नों पर पूरी तरह से निर्भर है, नीचे दी गई सबसे सामान्य क्वेरी है:
SELECT * FROM homes
WHERE geolat BETWEEN ??? AND ???
AND geolng BETWEEN ??? AND ???
अद्यतन 2:
निम्नलिखित डेटाबेस स्कीमा के साथ:
CREATE TABLE IF NOT EXISTS `homes` (
`home_id` int(10) unsigned NOT NULL auto_increment,
`primary_photo_group_id` int(10) unsigned NOT NULL default '0',
`customer_id` bigint(20) unsigned NOT NULL,
`account_type_id` int(11) NOT NULL,
`address` varchar(128) collate utf8_unicode_ci NOT NULL,
`city` varchar(64) collate utf8_unicode_ci NOT NULL,
`state` varchar(2) collate utf8_unicode_ci NOT NULL,
`zip` mediumint(8) unsigned NOT NULL,
`price` mediumint(8) unsigned NOT NULL,
`sqft` smallint(5) unsigned NOT NULL,
`year_built` smallint(5) unsigned NOT NULL,
`num_of_beds` tinyint(3) unsigned NOT NULL,
`num_of_baths` decimal(3,1) unsigned NOT NULL,
`num_of_floors` tinyint(3) unsigned NOT NULL,
`description` text collate utf8_unicode_ci,
`geolat` decimal(10,6) default NULL,
`geolng` decimal(10,6) default NULL,
`display_status` tinyint(1) NOT NULL,
`date_listed` timestamp NOT NULL default CURRENT_TIMESTAMP,
`contact_email` varchar(100) collate utf8_unicode_ci NOT NULL,
`contact_phone_number` varchar(15) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`home_id`),
KEY `customer_id` (`customer_id`),
KEY `city` (`city`),
KEY `num_of_beds` (`num_of_beds`),
KEY `num_of_baths` (`num_of_baths`),
KEY `geolat` (`geolat`),
KEY `geolng` (`geolng`),
KEY `account_type_id` (`account_type_id`),
KEY `display_status` (`display_status`),
KEY `sqft` (`sqft`),
KEY `price` (`price`),
KEY `primary_photo_group_id` (`primary_photo_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=8 ;
निम्न एसक्यूएल का उपयोग:
EXPLAIN SELECT homes.home_id,
address,
city,
state,
zip,
price,
sqft,
year_built,
account_type_id,
num_of_beds,
num_of_baths,
geolat,
geolng,
photo_id,
photo_url_dir
FROM homes
LEFT OUTER JOIN home_photos ON homes.home_id = home_photos.home_id
AND homes.primary_photo_group_id = home_photos.home_photo_group_id
AND home_photos.home_photo_type_id = 2
WHERE homes.display_status = true
AND homes.geolat BETWEEN -100 AND 100
AND homes.geolng BETWEEN -100 AND 100
EXPLAIN रिटर्न:
id select_type table type possible_keys key key_len ref rows Extra
----------------------------------------------------------------------------------------------------------
1 SIMPLE homes ref geolat,geolng,display_status display_status 1 const 2 Using where
1 SIMPLE home_photos ref home_id,home_photo_type_id,home_photo_group_id home_photo_group_id 4 homes.primary_photo_group_id 4
मुझे समझ में नहीं आया कि कैसे एक्सप्लेन कमांड पढ़ें। क्या यह अच्छा या बुरा लगता है। अभी, मैं जियोलेट और जियोलिंग के लिए एक समग्र सूचकांक का उपयोग नहीं कर रहा हूं। क्या मुझे करना चाहिए?