简体   繁体   English

查询以获取SSRS报告参数和下拉选项的速度较慢

[英]Query to get SSRS report parameters and Drop Down options slow

I need to get a list of parameters for a specific SSRS report and show all the possible drop down items available (along with Report parameter name, DataType, and Prompt). 我需要获取特定SSRS报告的参数列表,并显示所有可用的下拉项(以及报告参数名称,数据类型和提示)。

I'm not sure of other options (if there are any). 我不确定其他选项(如果有的话)。 The query returns exactly what I need, it just takes too long to be useful (10-12 seconds). 查询完全返回我需要的内容,它只需要很长时间才能有用(10-12秒)。 Is there another way to get these results or make this one faster? 有没有其他方法来获得这些结果或使这一结果更快?

USE ReportServer
DECLARE @dbname VARCHAR(25)
SET @dbname='DBName'
DECLARE @rptlistStr VARCHAR(MAX)
DECLARE @reportlist table ( path varchar(500), name varchar(500) )
insert into @reportlist
exec [ADA Master].[dbo].[spGetAdminReports] @dbname

set @rptlistStr = substring((SELECT ( ', ' + Name ) FROM @reportlist WHERE NAME = 'rptReport'
FOR XML PATH( '' )
), 3, 1000 )          


SELECT NAME, PATH,
y.r.query ('for $s in *:ParameterValue/*:Value return concat(data($s),"|")') [DropDownItemValue]    
, y.r.query ('for $s in *:ParameterValue/*:Label return concat(data($s),"|")') [DropDownItemLabel]      
, x.r.value ('@Name', 'VARCHAR(100)') AS ReportParameterName
, x.r.value ('*:DataType[1]', 'VARCHAR(100)') AS DataType
, x.r.value ('*:AllowBlank[1]', 'VARCHAR(50)') AS AllowBlank
, x.r.value ('*:Prompt[1]', 'VARCHAR(100)') AS Prompt
, x.r.value ('*:Hidden[1]', 'VARCHAR(100)') AS Hidden
, x.r.value ('*:MultiValue[1]', 'VARCHAR(100)') AS MultiValue
FROM (
SELECT  PATH
, NAME
, CAST(CAST(content AS VARBINARY(MAX)) AS XML) AS ReportXML 
FROM ReportServer.dbo.Catalog 
join master.dbo.ufn_SplitStringArray(@rptlistStr,',') a on NAME COLLATE DATABASE_DEFAULT = a.Item COLLATE DATABASE_DEFAULT
WHERE CONTENT IS NOT NULL AND TYPE = 2
) C
CROSS APPLY C.ReportXML.nodes('*:Report/*:ReportParameters/*:ReportParameter') x(r) 
OUTER APPLY x.r.nodes('*:ValidValues/*:ParameterValues') y(r) 
where x.r.value ('*:Prompt[1]', 'VARCHAR(100)') is not null 

First and foremost - I would not query ReportServer.dbo.Catalog directly; 首先 - 我不会直接查询ReportServer.dbo.Catalog; people do this all the time and it's crazy. 人们总是这样做,这很疯狂。 Converting img data into VARNBINARY(MAX) then into XML is insanely expensive. 将img数据转换为VARNBINARY(MAX)然后转换为XML非常昂贵。 If you need this information often I suggest dumping the results of this query into another table (we'll call it "SSRS_RDL") then, as part of your Report Deployment process you would update SSRS_RDL with changes and new records as needed. 如果您经常需要此信息,我建议将此查询的结果转储到另一个表 (我们将其称为“SSRS_RDL”),然后,作为报告部署过程的一部分,您将根据需要更新SSRS_RDL以及更改和新记录。 Even an hourly job that does this will often be enough. 即使每小时完成这项工作也足够了。 This way you're dealing with relational data that is easy to index and can be retreived 1000's of times faster than how you are doing it now. 通过这种方式,您可以处理易于索引的关系数据,并且可以比现在更快地检索1000倍。

That said you have a serious design flaw with your code; 那说你的代码存在严重的设计缺陷; you are: 你是:

  1. executing [ADA Master].[dbo].[spGetAdminReports] to push rows into your @reportlist table 执行[ADA Master]。[dbo]。[spGetAdminReports]将行推入@reportlist表
  2. then using XML PATH to turn @reportlist into a string called @rptlistStr 然后使用XML PATH将@reportlist转换为名为@rptlistStr的字符串
  3. Then using dbo.ufn_SplitStringArray to turn @rptlistStr back into a table 然后使用dbo.ufn_SplitStringArray将@rptlistStr变回表格
  4. Joining the results of this table to ReportServer.dbo.Catalog 将此表的结果连接到ReportServer.dbo.Catalog

You can get rid of @rptlistStr and the code to populate it from @reportList, and instead join your @reportlist table to ReportServer.dbo.Catalog. 您可以删除@rptlistStr以及从@reportList填充它的代码,而是将您的@reportlist表连接到ReportServer.dbo.Catalog。 In other words, change: 换句话说,改变:

FROM ReportServer.dbo.Catalog AS c
JOIN master.dbo.ufn_SplitStringArray(@rptlistStr,',') a on NAME COLLATE DATABASE_DEFAULT = a.Item COLLATE DATABASE_DEFAULT

To: 至:

FROM ReportServer.dbo.Catalog AS c
JOIN @reportlist AS a ON on c.Name COLLATE DATABASE_DEFAULT = a.name COLLATE DATABASE_DEFAULT

Lastly: 最后:

This query will run much faster with a parallel execution plan. 使用并行执行计划,此查询将运行得更快。 Once you've made the changes I just outline consider using OPTION (QUERYTRACEON 8649) at the end of your final SELECT query (or using Make_Parallel() by Adam Machanic.) 一旦你做了改变,我只想考虑在最后的SELECT查询结束时使用OPTION (QUERYTRACEON 8649) (或者使用Adam Machanic的Make_Parallel())。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM