MySQL “IN” operator performance on (large?) number of values

后端 未结 6 734
囚心锁ツ
囚心锁ツ 2020-11-28 03:26

I have been experimenting with Redis and MongoDB lately and it would seem that there are often cases where you would store an array of id\'s in either Mongo

6条回答
  •  攒了一身酷
    2020-11-28 04:10

    You can create a temporary table where you can put any number of IDs and run nested query Example:

    CREATE [TEMPORARY] TABLE tmp_IDs (`ID` INT NOT NULL,PRIMARY KEY (`ID`));
    

    and select:

    SELECT id, name, price
    FROM products
    WHERE id IN (SELECT ID FROM tmp_IDs);
    

提交回复
热议问题