Domanda

mysql query takes more than 1 day, how to speet it up :

update posts set  category_id = (
    SELECT keyword_id 
    FROM post_keywords 
    where  keyword_id IN (
        SELECT  keyword_id  
        FROM post_keywords 
        where  id_post = posts.id_post)  
    group by keyword_id 
    order by count(keyword_id) DESC 
    limit 0,1
);  

any solution ?

È stato utile?

Soluzione

It's not entirely the same thing, yet the outcome will still be what you want it to be I think. I'm mostly curious to how (IF!?) this might affect the performance.

UPDATE posts 
   SET category_id = (
                        SELECT pkw.keyword_id
                          FROM post_keywords pkw
                          JOIN (
                                    SELECT keyword_id, cnt = COUNT(*)
                                      FROM post_keywords 
                                     GROUP BY keyword_id ) cnts
                            ON cnts.keyword_id = pkw.keyword_id
                         WHERE pkw.id_post = posts.id_post
                         ORDER BY cnt DESC 
                         LIMIT 0,1

                    )
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top