Share via

SQL Server could not produce query plan while querying view containing reference to External Table

Justin Elemans 1 Reputation point
2021-12-10T10:40:44.667+00:00

Hello, I have the following problem. Hopefully somebody can help me with it.

Error given back by SQL server:
Msg 8624, Level 16, State 1, Line 1
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.

Situation:

  • Two databases on one Azure Database server, one called sqldb-DWH and the other called sqldb-Prepared
  • Table in sqldb-Prepared named [dbo].[Ticket_tmp]
  • External Table in sqldb-DWH called [dbo].[Ticket_tmp] referencing [sqldb-Prepared].[dbo].[Ticket_tmp]
  • View referencing this External Table

Since I had issues adding attachment, see below section ObjectDefinitions for the exact definition of mentioned objects. The table [sqldb-Prepared].[dbo].[Ticket_tmp] is only filled with INT values 1 up through 5 (so 5 records)

Issue:

When performing the following query on the view the error occurs:
SELECT [TicketNo] ,[TicketType] FROM [dbo].[vw_Ticket_tmp] WHERE [TicketType] = 'Something' (or likewise when [TicketType = 'SomethingElse')

When the whole list of possible values of [TicketType] is provided, no error occurs. This can be acchieved either two ways:
SELECT [TicketNo] ,[TicketType] FROM [dbo].[vw_Ticket_tmp] (so removal of WHERE clause)
or
SELECT [TicketNo] ,[TicketType] FROM [dbo].[vw_Ticket_tmp] WHERE [TicketType] IN ('Something', 'SomethingElse') (so inclusion of all possible values in WHERE clause)

This only seems to be the case for putting a WHERE clause on the field that was manually added in the view, in this case [TicketType]. For example the following does not returns the error:
SELECT [TicketNo] ,[TicketType] FROM [dbo].[vw_Ticket_tmp] WHERE [TicketNo] = 3

ObjectDefinitions

-- Database: sqldb-Prepared --

/****** Object: Table [dbo].[Ticket_tmp] Script Date: 10-12-2021 11:24:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Ticket_tmp](
[TicketNo] [int] NULL
) ON [PRIMARY]
GO

INSERT INTO [dbo].[Ticket_tmp] VALUES (1), (2), (3), (4), (5)

-- Database: sqldb-DWH --

/****** Object: Table [dbo].[Ticket_tmp] Script Date: 10-12-2021 11:24:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE EXTERNAL TABLE [dbo].[Ticket_tmp]
(
[TicketNo] [int] NULL
)
WITH (DATA_SOURCE = [Prepared],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'Ticket_tmp')
GO
/****** Object: View [dbo].[vw_Ticket_tmp] Script Date: 10-12-2021 11:24:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_Ticket_tmp] AS

SELECT [TicketNo]
,[TicketType] = 'Something'
FROM [dbo].[Ticket_tmp]

UNION

SELECT [TicketNo]
,[TicketType] = 'SomethingElse'
FROM [dbo].[Ticket_tmp]
GO

Thanks in advance!
Justin

Azure SQL Database

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.