Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.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
Performance 带列的性能SQL Where子句_Performance_Tsql_Sql Server 2014_Where - Fatal编程技术网

Performance 带列的性能SQL Where子句

Performance 带列的性能SQL Where子句,performance,tsql,sql-server-2014,where,Performance,Tsql,Sql Server 2014,Where,我有两个表,看看“正常的归属”(a)从某个日期起是否有效。以及有取消日期的“试用订阅”(B) TABLE A ValidFrom id 2022-09-24 1 2022-01-25 2 TABLE B id cancellationDate 1 2023-07-16 2 2023-07-16 1 2023-06-05 2 2019-07-04 1 2016-10-01 1 2023-12-16 1 2017-10-28 通过尝试确定试用期后是否有订阅,

我有两个表,看看“正常的归属”(a)从某个日期起是否有效。以及有取消日期的“试用订阅”(B)

TABLE A
ValidFrom   id
2022-09-24  1
2022-01-25  2

TABLE B
id  cancellationDate
1   2023-07-16
2   2023-07-16
1   2023-06-05
2   2019-07-04
1   2016-10-01
1   2023-12-16
1   2017-10-28
通过尝试确定试用期后是否有订阅,我创建了以下查询

 SELECT        
      Sales.B.CancellationDate
     ,Y.ValidFrom  
 FROM            Sales.A AS Y  
 INNER JOIN 
     Sales.B ON Y.id = Sales.B.id 
 WHERE
     Sales.B.CancellationDate >  Y.ValidFrom
     ORDER BY 1
将返回以下内容:

CancellationDate    ValidFrom
2023-06-05  2022-09-24
2023-07-16  2022-09-24
2023-07-16  2022-01-25
2023-12-16  2022-09-24

<强>我想知道是否有一个更好的方法来改善以下的性能:(考虑索引是否存在)< /强>

Sales.B.CancellationDate >  Y.ValidFrom 
我感觉DB引擎正在进行N x M比较,以便得到结果并执行布尔值true

编辑:

索引/表格:

CLUSTERED INDEX [ClusteredIndex-20181107-194645] ON [Sales].[B](    [id] ASC)
CLUSTERED INDEX [ClusteredIndex-20181107-194645] ON [Sales].[A](    [id] ASC)

CREATE TABLE [Sales].[A](
        [ValidFrom] [date] NULL,
        [id] [tinyint] NULL
    ) ON [PRIMARY]
CREATE TABLE [Sales].[B](
       [id] [tinyint] NULL,
       [cancellationDate] [date] NULL
) ON [PRIMARY]

您可以查看实际执行计划,以查看数据库引擎决定如何处理查询。(在SSMS:Query->Include Actual Execution Plan中)“考虑有索引”但在Dates列上没有显示任何索引-在这两个表中添加id和date列上的索引应该可以提高此查询的性能。您好,Zohar和HABO。即使我运行执行计划,向索引中添加新列,并正确设置所有索引(完美状态),是否有任何方法可以创建、写入WHERE子句,从而提供更好的性能<代码>Sales.B.CancellationDate>Y.ValidFrom