私はPHP/MYSQLでマルチストアWebショップアプリケーションを書いています。商品テーブルには約100万件のレコードがあり、現在、すべての商品が含まれる5つの店舗と、いくつかの商品が含まれる約3つの店舗があります。商品の価格は店舗によって異なる場合があります。たとえばショップ2だけで特定の商品を追加または削除できるはずなので、ジャンクションテーブルを作成しました。私のテーブルは次のようになります。
products(id,name,description,price,media) ~1M records
stores(id,name)
products_stores(id,product_id,store_id,price) ~5M records
商品を検索する場合、クエリには約20秒かかります。products(name、description)+ products_stores(product_id、store_id)にインデックスを追加しました。プロセスをスピードアップする方法はありますか?products_storesのほとんどのレコードは同じですが(store_idを除く)、柔軟性を維持したいと思います。
クエリ:
SELECT
Product.id,
Product.name,
Product.drager,
Product.import,
Product.price,
Product.description,
Product.units
FROM
products AS Product
INNER JOIN
products_stores AS ProductStore ON (
ProductStore.product_id = Product.id
AND
ProductStore.store_id =1
)
WHERE
name LIKE 'bach%'
ORDER BY
Product.description asc
LIMIT
500
名前のみにFULLTEXTインデックスを追加し、ORDER BYステートメントを削除しましたが、違いはないようです。私のインデックスは次のとおりです。
Products(name) BTREE
Products(name,description) FULLTEXT
Products(name) FULLTEXT
上記のクエリの説明は次のようになります:(インデックス付き) http://i.stack.imgur.com/8Fe8C.gif
よろしくお願いします。英語が下手でごめんなさい。