简体   繁体   English

SQL Server:在包含Json Object的列上使用IS NOT Null的where子句中的查询应用时间更长

[英]SQL Server : query apply in where clause with IS NOT Null on Column that contains Json Object taking more time

I have a table in a SQL Server database that columns contain JSON object and that column I iterating through where clause condition with IN NOT NULL, by using openJson JSON_Value and JSON_Query function.The query is running successfully but it taking more time to response output.only in 4 rows taking 7sec. 我在SQL Server数据库中有一个表,该表的列包含JSON对象,并且我使用openJson JSON_Value和JSON_Query函数使用IN NOT NULL遍历where子句条件。该查询已成功运行,但需要更多时间来响应输出。仅在4行中耗时7秒。 Then what about if table having 1000 of rows. 那如果表有1000行呢?

Table looks lie this: 表看起来像这样:

在此处输入图片说明

在此处输入图片说明

Here is the query on table that's I'm using: 这是我正在使用的表查询:

SELECT TOP (1000) 
    [Id], JSON_Value(objectJson,'$.Details.Name.Value') AS objectValue 
FROM  
    [geodb].[dbo].[userDetails]
WHERE
    JSON_QUERY(jsonData,'$."1bf1548c-3703-88de-108e-bf7c4578c912"') IS NOT NULL

So, how to optimize above query so that it takes less time? 那么,如何优化上述查询,以减少时间呢?

I would suggest altering the table: 我建议更改表:

ALTER TABLE dbo.Table
ADD Value AS JSON_VALUE(JsonData, '$.Details.Name.Value');

then creating a non clustered index on value column 然后在值列上创建非聚集索引

CREATE NONCLUSTERED INDEX IX_ParsedValue ON dbo.Table (Value)

This will speed up the query. 这样可以加快查询速度。

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

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