且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查 mySQL 中现有条目的***方法是什么?(简单的表结构,大量的数据)

更新时间:2021-10-30 08:42:14

出于性能原因,我会在一个查询中选择所有数字.

For performance reasons I would select all numbers in one query.

SELECT `numbers` FROM `phone_numbers` WHERE `number` IN('123', '456', '789')

然后您可以迭代结果并检查其中是否包含数字.如果不包含数字,则将其附加到您的插入查询中.所以你只有两个查询.一个用于选择,一个用于插入.

Then you can iterate over the result and check if a number is contained in it or not. If a number isn't contained then append it to your insert query. So you have only two queries. One for select and one for insert.

关于您的性能问题.您应该在存储电话号码的字段上有一个索引.

To your performance question. You should have an index on your field which stores the phone numbers.