检查数据库集中是否存在集合的最快方法 [英] Fastest way to check if set exists in database set

查看:56
本文介绍了检查数据库集中是否存在集合的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个数据库,其中包含数百万个网址,还有数百万个网址.我需要一种快速的方法来检查数据库中是否存在一批 url.目前我有这个:

foreach($urls as $url) {$this->db->or_where('url', $url->url);}

产生这样的查询:

WHERE url = 'foo' OR url = 'bar' OR ...

是否有更快的方法来检查数据库中是否存在数据集?

解决方案

有点像:

<前><代码>SELECT EXISTS(SELECT 1 FROM table1 url = 'foo' OR url = 'bar' OR ...)

Say I have a database with millions of urls with millions more to come. I need a fast way of checking if a batch of urls exist in the database. At the moment I have this:

foreach($urls as $url) {
  $this->db->or_where('url', $url->url);
}

Which produces queries like this:

WHERE url = 'foo' OR url = 'bar' OR ...

Are there faster ways to check if sets of data exist in a database?

解决方案

Someting like:


SELECT EXISTS(SELECT 1 FROM table1 url = 'foo' OR url = 'bar' OR ...
)


这篇关于检查数据库集中是否存在集合的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆