Getting 502 on join eloquent laravel

Posted on

Question :

I need to get distinct value using inner join. Here is query

    SELECT  distinct(ad_camp_sid.cid)
        from  ad_camp_sid
        inner join  ad_dsp_sites  ON ad_dsp_sites.site_id = ad_camp_sid.sid
        where  ad_dsp_sites.exchange = 4 

table has records count as below:
ad_camp_sid = 25602
ad_dsp_sites = 371173

Here ad_camp_sid.cid has thousands of records. I have added index on columns as well. Still its not responding.
Can i user alternative or any solution for same.

Please suggest me.

Answer :

Add these composite indexes:

ad_camp_sid:  INDEX(sid,  cid)
ad_dsp_sites:  INDEX(exchange, site_id)

When adding a composite index, DROP index(es) with the same leading columns.
That is, when you have both INDEX(a) and INDEX(a,b), toss the former.

Leave a Reply

Your email address will not be published.