Search

Plan Regression with Sequence Projections by Paul White NZ

Active

3
0
Sign in
to vote
Type: Bug
ID: 727419
Opened: 2/29/2012 8:41:51 PM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
In SQL Server 2008, the optimizer is able to push suitable predicates below a sequence project. In 2008 R2, pushing selections is broken for sequence projections that require a segment apply, namely NTILE and windowed aggregates. (This regression does not appear, or is fixed, in SQL Server 2012).

(tested on 2008 build 5768 and R2 build 2806)

USE tempdb;
GO
CREATE TABLE dbo.T (x int PRIMARY KEY, y int)
GO
-- Predicate successfully pushed in both 2008 and R2
SELECT z.* FROM
(
    SELECT
        t.x,
        t.y,
        rn = ROW_NUMBER() OVER(
            PARTITION BY t.x
            ORDER BY t.y)
    FROM dbo.T AS t
) AS z
WHERE z.x = 1;
GO
-- Predicate pushed to a seek on 2008
-- Not pushed on 2008 R2
SELECT z.* FROM
(
    SELECT
        t.x,
        t.y,
        rn = MAX(t.y) OVER(
            PARTITION BY t.x)
    FROM dbo.T AS t
) AS z
WHERE z.x = 1;
GO
-- Pushed to a seek on 2008
-- No seek and COUNT(*) computed *twice* on 2008 R2
SELECT z.* FROM
(
    SELECT
        t.x,
        t.y,
        rn = NTILE(4) OVER(
            PARTITION BY t.x
            ORDER BY t.y)
    FROM dbo.T AS t
) AS z
WHERE z.x = 1;
GO


Details (expand)

Product Language

English

Version

SQL Server 2008 R2 - Developer Edition

Category

SQL Engine

Operating System

Not Applicable

Operating System Language

Not Applicable

Steps to Reproduce

USE tempdb;
GO
CREATE TABLE dbo.T (x int PRIMARY KEY, y int)
GO
-- Predicate successfully pushed in both 2008 and R2
SELECT z.* FROM
(
    SELECT
        t.x,
        t.y,
        rn = ROW_NUMBER() OVER(
            PARTITION BY t.x
            ORDER BY t.y)
    FROM dbo.T AS t
) AS z
WHERE z.x = 1;
GO
-- Predicate pushed to a seek on 2008
-- Not pushed on 2008 R2
SELECT z.* FROM
(
    SELECT
        t.x,
        t.y,
        rn = MAX(t.y) OVER(
            PARTITION BY t.x)
    FROM dbo.T AS t
) AS z
WHERE z.x = 1;
GO
-- Pushed to a seek on 2008
-- No seek and COUNT(*) computed *twice* on 2008 R2
SELECT z.* FROM
(
    SELECT
        t.x,
        t.y,
        rn = NTILE(4) OVER(
            PARTITION BY t.x
            ORDER BY t.y)
    FROM dbo.T AS t
) AS z
WHERE z.x = 1;
GO

Actual Results

Predicates pushed on SQL Server 2008, not pushed on SQL Server 2008 R2.

Expected Results

Same plans for 2008 and R2.

Platform

X64

Virtualization

 
File Attachments
0 attachments
Sign in to post a comment.
Sign in to post a workaround.