在localserver(SQL Server 2008 R2)上,我有一个名为syn_view1
指向链接服务器的同义词remoteserver.remotedb.dbo.view1
此SLOW查询需要20秒才能运行.
select e.column1, e.column2
from syn_view1 e
where e.column3 = 'xxx'
and e.column4 = 'yyy'
order by e.column1
Run Code Online (Sandbox Code Playgroud)
此FAST查询需要1秒才能运行.
select e.column1, e.column2
from remoteserver.remotedb.dbo.view1 e
where e.column3 = 'xxx'
and e.column4 = 'yyy'
order by e.column1
Run Code Online (Sandbox Code Playgroud)
两个查询的唯一区别实际上是同义词的存在.显然,同义词会影响查询的性能.
SLOW查询的执行计划是:
Plan Cost % Subtree cost
4 SELECT
I/O cost: 0.000000 CPU cost: 0.000000 Executes: 0
Cost: 0.000000 0.00 3.3521
3 Filter
I/O cost: 0.000000 CPU cost: 0.008800 Executes: 1
Cost: 0.008800 …
Run Code Online (Sandbox Code Playgroud) sql-server performance linked-server synonym sql-server-2008-r2
所以我通过powershell调用一个休息Web服务,如果你试图发布已经处理过的数据,它会响应一个400状态代码,以及状态代码它还会返回一个JSON响应:
{
"statusCode": 400,
"errorCode": "REQUEST_VALIDATION_ERROR",
"message": "validation failed",
"developerMessage": " MessageId-xxx already processed. No Need to process again."
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试用一些powershell调用它并接收400状态代码并使用try/catch来处理这个以获取异常,但是响应中没有内容,我可以获得响应头,状态代码,状态消息等,但是我根本找不到访问JSON响应的方法,这里是我正在使用的powershell代码的格式:
$url = "https://example.com/webservice/status"
$cert = Get-ChildItem Cert:\CurrentUser\My\certthumbprintxxxxx
$headers = @{"tokenId" = "tokenxxxxx"}
$body =
@"
{
...
JSON data...
...
}
"@
try
{
$response = Invoke-WebRequest $url -Certificate $cert -Headers $headers -Method Post -Body $body
}
catch
{
$_.Exception.response
}
Run Code Online (Sandbox Code Playgroud)
当我发送$_.Exception.response
给Get-Member时,我可以看到没有内容属性.如何使用PowerShell访问响应中的消息?