MySQL-不在(....庞大的项目...),它会扩展吗? [英] MySQL - NOT IN (.... a gazillion items ... ), will it scale?

查看:63
本文介绍了MySQL-不在(....庞大的项目...),它会扩展吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将尝试访问记录,但是将使用如下语法排除具有ID列表的记录:

I'm going to be trying to access records, but will exclude records with, say, a list of ids using a syntax like this:

不在其中的ID(1,3,4,6,7,...

随着数据库的扩大, ID列表也会越来越大。有一天我会遇到问题吗?

As my database gets bigger, that list of ids will also get bigger. Am I going to have a problem someday?

推荐答案

考虑存储要排除的ID列表在另一个表中,然后使用以下SQL:

Consider storing the list of ids to exclude in a different table, then use the following SQL:

WHERE id NOT IN (select id from excluded_ids);

将索引放在<$ c $的 id 列上c> excluded_ids 的可扩展性。

Put an index on the id column of excluded_ids for scalabilty.

这篇关于MySQL-不在(....庞大的项目...),它会扩展吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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