検索結果を返すために使用する MySQL のビューに基づくレコードセットがありますが、非常に遅いです (一貫して 21 秒!)。同じ環境での同様の検索には、1 秒もかかりません。
検索で関連データを利用できるようにするために 4 つの左結合と 1 つのサブクエリがあるため、速度が低下しているのはビューではないかと心配しています。
ビューを使用するときにクエリを高速化するための一般的なガイダンスはありますか? インデックス作成について調査しましたが、MySQL ではビューで許可されていないようです。
ご提案いただきありがとうございます。
ビューを作成するコード:
CREATE VIEW vproducts2 AS
SELECT products2.productid, products2.active, products2.brandid,
products2.createddate, products2.description, products2.inventorynum,
products2.onhold, products2.price, products2.refmodnum, products2.retail,
products2.sefurl, products2.series, products2.sold,
`producttype`.`type` AS type, categories.category AS category,
`watchbrands`.`brand` AS brand, productfeatures.productfeaturevalue AS size,
(SELECT productimages.image
FROM productimages
WHERE productimages.productid = products2.productid
LIMIT 1
) AS pimage
FROM products2
LEFT JOIN producttype ON producttype.typeid = products2.typeid
LEFT JOIN categories ON categories.categoryid = products2.categoryid
LEFT JOIN watchbrands ON watchbrands.brandid = products2.brandid
LEFT JOIN productfeatures ON productfeatures.productid = products2.productid
AND productfeatures.featureid = 1