select
xml_record_product.product_id,
IfNull(xml_record_product.product_short_description,xml_record_product.product_description) AS BookDescription,
xml_record_product.product_image,
xml_record_product.product_publisher_name AS Publisher,
xml_record_product.product_title AS BookTitle,
xml_record_product.product_form,
xml_record_product.product_num_pages,
xml_record_product.product_BASICMainSubject,
xml_record_product.product_BICMainSubject,
xml_record_product.product_audience_code,
xml_record_product.product_country_of_publication,
xml_record_product.product_publishing_status,
xml_record_product.product_publication_date AS BookDate,
xml_record_product.product_imprint,
xml_record_product.product_active,
xml_record_product.product_isFeatured,
xml_record_product.product_isNewArival,
xml_record_product.product_short_description,
xml_record_product.product_description,
xml_record_product.product_isbn13 AS ISBN,
xml_record_subject.subject_heading_text
FROM xml_record_product
inner join xml_record_contributor ON xml_record_product.product_id = xml_record_contributor.product_id
inner join xml_record_subject on xml_record_contributor.product_id = xml_record_subject.product_id
inner join xml_record_supplier on xml_record_product.product_id = xml_record_supplier.product_id AND supplier_price > 0
where contributor_title like '%josh%'
order by xml_record_product.product_publication_date DESC limit 20;
SIMPLE xml_record_supplier index sup_product_id sup_product_id 265 895424 Using where; Using index; Using temporary; Using filesort
SIMPLE xml_record_subject ref product_id_sub product_id_sub 8 mysupplier1.xml_record_supplier.product_id 1
SIMPLE xml_record_product eq_ref PRIMARY PRIMARY 8 mysupplier1.xml_record_supplier.product_id
SIMPLE xml_record_contributor ref cont_product_id cont_product_id 8 mysupplier1.xml_record_subject.product_id 1 Using where
但如果我拿出內部聯接上xml_record_supplier,我得到這個:
SIMPLE xml_record_product index PRIMARY pub_date 265 20
SIMPLE xml_record_subject ref product_id_sub product_id_sub 8 mysupplier1.xml_record_product.product_id 1
SIMPLE xml_record_contributor ref cont_product_id cont_product_id 8 mysupplier1.xml_record_subject.product_id 1 Using where
我需要知道爲什麼會這樣,以及它如何防止?據我瞭解,EXPLAIN會顯示從內連接順序讀取的表。這沒有發生,並且我確信我在這些查詢上有product_id的索引集(對於xml_record_contributor,它是product_id和contributor_id的混合)
在xml_record_supplier上,索引中有product_id和supplier_price(但是,我也嘗試了很多組合,認爲所有這些)
任何想法我可以嘗試嗎?我需要將選擇範圍限制在價格高於0的供應商,並且加入內部連接後,它很快就會失控。
感謝您的任何意見!
/編輯 - 這裏的所有表的描述
xml_record_product (index is product_id,product_publication_date desc)
product_id bigint(20) NO PRI auto_increment
product_isbn13 bigint(13) NO
product_form varchar(255) NO
product_num_pages int(11) NO
product_BASICMainSubject varchar(255) NO
product_BICMainSubject varchar(255) NO
product_audience_code int(11) NO
product_country_of_publication varchar(255) NO
product_publishing_status int(11) NO
product_publication_date varchar(255) NO MUL
product_short_description varchar(350) NO
product_description text NO
product_imprint varchar(255) NO
product_image varchar(255) NO
product_publisher_name varchar(255) NO
product_title varchar(255) NO
product_active int(11) NO 1
cat_id int(11) NO
product_isFeatured int(11) NO
product_isNewArival int(11) NO
xml_record_contributor(指數PRODUCT_ID,contributor_id)
contributor_id int(11) NO PRI auto_increment
product_id bigint(20) NO MUL
contributor_title varchar(255) NO
xml_record_supplier(指數PRODUCT_ID,supplier_id,supplier_price)
supplier_id int(11) NO PRI auto_increment
product_id bigint(20) NO MUL
supplier_name varchar(255) NO
supplier_product_availability int(11) NO
supplier_price varchar(255) NO
supplier_currency_code varchar(255) NO
supplier_supply_to varchar(255) NO
supplier_price_status varchar(255) NO
Description text NO
URL varchar(255) NO
Image1 varchar(255) NO
Image1_sml varchar(255) NO
Image1Alt varchar(255) NO
xml_record_subject(index is subject_id,product_id)
subject_id int(11) NO PRI auto_increment
product_id bigint(20) NO MUL
subject_heading_text varchar(255) YES MUL
ParentID varchar(20) NO
編輯
這裏是SHOW INDEX從xml_record_supplier
xml_record_supplier 1 sup_product_id 1 product_id A 447712 BTREE
xml_record_supplier 1 sup_product_id 2 supplier_id A 895424 BTREE
xml_record_supplier 1 sup_product_id 3 supplier_price A 895424 BTREE
這些索引是否爲複合索引? SHOW INDEXES FROM表格會爲您提供表格中的所有索引。 – robdog 2010-07-27 09:17:34
我在表格中添加了顯示索引(當內部連接時)。我不完全確定它是否是一個複合索引,但我相信它一定是。 – AcidRaZor 2010-07-27 14:32:12