Ben şimdi bir kaç gün için bu soruna bir çözüm arıyor oldum ve bu sorguyu çalıştırmak için gereken süreyi azaltmak verecek bir şey bulamadı.
Ben 2 tablolar var:
"product_db":
unique_id - [index]
image
url_title
status - [index]
"product_page"
id
product_unique_id - [index]
page_id - [index]
Ne seçmek istiyorum status = 'Çevrimiçi' ve ürün sayfası id = 3 olmalıdır product_db rastgele bir görüntü
product_db 90.000 'den fazla ürün var ve product_page 150000 üzerinde satır var.
Ben şimdi kullanıyorum sorgu:
SELECT image FROM product_db a, product_page b WHERE b.page_id = 3 AND a.status = 'Online' AND a.unique_id = b.product_unique_id ORDER BY RAND() LIMIT 1
This query takes around 2.3secs to run. This is quite a long time for a web page to load. I have tried a few other queries that first returns a random row from product_page with page_id = 3 and then querying product_db (it did reduce the time it takes) but the problem with that is I cannot compare if the product is 'Online' or not.