@CathyJi-MSFT , @Viorel , @Jeffrey Williams ,
Here is my VIEW definition. This has been working great with Powerapps and SQL 2014 Std for quite some time. With the upgrade to SQL 2019 Std and SP1 CU12, it has still worked, but it takes several minutes to update a table in Powerapps. No eerors, but SQL on the server is pegged the CPU, and memory usage shoots to the several gigabytes for the task. View results look appropriate when looking in SSMS (Full results in just over a minute). Not sure what to make of it. It still takes the same length of time to execute in SSMS too. Its just when there are several queries to the table, it acts as if the VIEW regenerates with every poll. I check the execution log, and the more polls made to the VIEW, the longer the response time. If you hit it once, its fine, but if a gallery hits the VIEW say 20 times, I saw some instances taking over 800seconds to respond. My theory is if this were simply a table of data, not a VIEW, that it would be much quicker. So, I wanted to try pushing the VIEW to a table every 5-10 minutes, then connecting to this table for Powerapps.
Here is the definition.
WITH cte
AS (SELECT *
FROM dbo.variablevalue
WHERE ( 2 = CASE
WHEN ( variableid = 73
OR variableid = 74
OR variableid = 75
OR variableid = 76 )
AND configurationid = 2 THEN 2
WHEN NOT ( variableid = 73
OR variableid = 74
OR variableid = 75
OR variableid = 76 ) THEN 2
END )),
all_combined
AS (SELECT TOP (100) PERCENT documentid,
[49] AS [DwgRevision],
[47] AS [Description],
[45] AS [ProjectName],
[54] AS [PartNumber],
currentstatusid,
pending,
latestrevisionno,
filename,
[57] AS [Version],
[56] AS [Material],
[73] AS [RvTbl_Description],
[76] AS [RvTbl_DwgDate],
[75] AS [RvTbl_Approved],
[74] AS [RvTbl_Revision],
transitionid
FROM (SELECT documentid,
variableid,
textoutput,
currentstatusid,
filename,
transitionid,
latestrevisionno,
CASE
WHEN currentstatusid <> 10 THEN 1
ELSE 0
END AS Pending
FROM (SELECT cte.documentid,
cte.variableid,
documents.currentstatusid,
dbo.transitionhistory.transitionid,
documents.filename,
documents.latestrevisionno,
cte.configurationid,
cte.revisionno,
cte.valuetext
AS TextOutput,
Row_number()
OVER (
partition BY cte.documentid, cte.variableid
ORDER BY cte.revisionno DESC,
dbo.transitionhistory.transitionnr
DESC) AS
Seq
FROM dbo.documents
INNER JOIN cte
ON dbo.documents.documentid =
cte.documentid
INNER JOIN dbo.transitionhistory
ON dbo.documents.documentid =
dbo.transitionhistory.documentid
WHERE ( dbo.documents.deleted = 0 )
AND ( dbo.documents.extensionid = 3 )
AND ( dbo.documents.currentstatusid <> 0 )
AND cte.variableid IN ( 57, 56, 54, 49,
47, 45, 73, 76,
75, 74 )) t
WHERE seq = 1) doc
PIVOT (Max(textoutput)
FOR variableid IN ([57],
[56],
[54],
[49],
[47],
[45],
[73],
[76],
[75],
[74])) AS pvt
WHERE [54] <> 'NULL')
SELECT all_combined.*,
dbo.documentsinprojects.projectid
FROM dbo.documentsinprojects
INNER JOIN all_combined
ON dbo.documentsinprojects.documentid = all_combined.documentid