简体   繁体   English

SQL查询大数据库中的大数据过滤器

[英]SQL query for large data filter from big database

I have a large database on server. 我在服务器上有一个大型数据库。 The database is all about the mobile numbers with about 20 millions of records at present. 该数据库目前包含约2000万条记录的手机号码。 I want to match the mobile numbers on my website to filter the DND or Non-DND mobile numbers. 我想匹配网站上的手机号码以过滤DND或非DND手机号码。 I am using this query for small number filtering 我正在使用此查询进行小数过滤

SELECT phone_number
FROM mobnum_table
WHERE phone_number IN ('7710450282', '76100003451', '8910003402', '9410009850', '7610000191');

But what about in the condition I want to filter 1,00,000 mobile number records in few seconds..? 但是如果我想在几秒钟内过滤掉1000万个手机号码记录,那该怎么办? I heard about SQL query optimization but not aware so much about it. 我听说过SQL查询优化,但是对此了解不多。 Also please guide me what storage engine should I consider in this situation? 另外,请指导我在这种情况下应考虑使用哪种存储引擎?

I have already googled it, but didn't find so much good answer for the same. 我已经用谷歌搜索过,但是没有找到很好的答案。

Thanks in Advance.. 提前致谢..

I think there is some problem in your requirement itself. 我认为您的需求本身存在一些问题。 If you tell us more about your problem, may be we can help you. 如果您告诉我们更多有关您的问题的信息,也许我们可以为您提供帮助。 Anyway its not a good idea to give all the 100000 numbers in IN . 无论如何,给IN所有100000个数字不是一个好主意。 One option is to create another table and do an inner join. 一种选择是创建另一个表并进行内部联接。

Assume you have another table selectednumbers with columns id and phone_number , you can do an inner join as follows 假设您有另一个表selectednumbers具有idphone_number列,则可以执行内部phone_number ,如下所示

SELECT phone_number FROM mobnum_table a inner join selectednumbers b on 
a.phone_number=b.phone_number

As I mentioned earlier, your question is not complete. 如前所述,您的问题还不完整。 So kindly provide some more information so we can give optimized query. 因此,请提供更多信息,以便我们提供优化的查询。

So you're generating a list of 100,000 numbers, and then putting that back into another query? 因此,您要生成100,000个数字的列表,然后将其放回另一个查询中?

If you're getting the numbers from a table, take the query that generated the list of numbers in the first place, put it inside the in() brackets, and you'll see a large improvement immediately. 如果要从表中获取数字,请首先查询生成数字列表的查询,将其放在in()括号内,您会立即看到很大的改进。

Restructure them both to use a JOIN, instead of in() and you'll see even more. 将它们都重组为使用JOIN而不是in(),您将看到更多。

OR, depending on your DB structure, just do 或者,根据您的数据库结构,只需执行

SELECT phone_number
FROM mobnum_table
WHERE DND = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM