Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 添加类似“%”的where子句是否会导致性能问题?_Sql_Oracle_Where Clause - Fatal编程技术网

Sql 添加类似“%”的where子句是否会导致性能问题?

Sql 添加类似“%”的where子句是否会导致性能问题?,sql,oracle,where-clause,Sql,Oracle,Where Clause,我正在编写一个查询,它将通过我的程序在数据库上执行。在该查询中,我添加了一个where子句,其中包含从客户机发送的值。在某些值不存在的情况下,我将其保留为空,即它将看起来像select*from tablename,其中columname类似于“%”,columname1类似于“%”。这会导致性能问题吗?回答此类问题的最佳方法是测试。您应该尝试带条件和不带条件的查询 向where子句添加条件至少可以通过三种方式影响性能: 条件会使优化器更难使用索引或为查询选择适当的分区。 条件可以改变表的选择性

我正在编写一个查询,它将通过我的程序在数据库上执行。在该查询中,我添加了一个where子句,其中包含从客户机发送的值。在某些值不存在的情况下,我将其保留为空,即它将看起来像select*from tablename,其中columname类似于“%”,columname1类似于“%”。这会导致性能问题吗?

回答此类问题的最佳方法是测试。您应该尝试带条件和不带条件的查询

向where子句添加条件至少可以通过三种方式影响性能:

条件会使优化器更难使用索引或为查询选择适当的分区。 条件可以改变表的选择性。如果优化器不知道要选择的行数,那么它可能会为连接和聚合选择效率较低的算法。 评估病情本身可能代价高昂。 如果您的查询很简单:

select t.*
from t
where col like '%%';
那么前两点就不相关了。第三个是稍微相关的。问题是数据库是否会因为模式是泛型的而进行类似的优化。我不认为是这样;它必须将其替换为col not null


使用like有一些开销。我想首先,like的开销要比阅读表格的开销小得多。因此,尽管它可能会影响性能,但在简单的情况下,影响相对较小。

请用您正在使用的数据库标记您的问题。根据该条件检查内容和生成查询是否会很复杂?