Azure / Azure/data-api-builder

Evaluate potential redundancies in our generated SQL query

Open
#2,413 0 comments 0 reactions 0 assignees View on GitHub
improvement triage
Dominant language
C#
Stars
1.5k
Forks
370
Avg merge
3d 17h
Merged PRs (30d)
8

Description

This issue is related to #2412. And aims at bringing further optimization.

The current generated SQL query for UPDATE/DELETE includes a second SELECT @ROWS_TO_UPDATE operation. We need to evaluate if this second SELECT is necessary or if it can be removed to further optimize the script.

## Current Generated Query
```
DECLARE @ROWS_TO_UPDATE int;

SET @ROWS_TO_UPDATE = (SELECT COUNT(*) as cnt_rows_to_update FROM [dbo].[todo] WHERE [dbo].[todo].[id] = @param0);

SELECT @ROWS_TO_UPDATE as cnt_rows_to_update;

IF @ROWS_TO_UPDATE = 1
BEGIN
UPDATE [dbo].[todo]
SET [dbo].[todo].[position] = @param1, [dbo].[todo].[owner_id] = @param2
OUTPUT Inserted.[id] AS [id], Inserted.[title] AS [title], Inserted.[completed] AS [completed], Inserted.[owner_id] AS [owner_id], Inserted.[position] AS [order]
WHERE [dbo].[todo].[id] = @param0;
END
```

## Objective
Determine if the second SELECT @ROWS_TO_UPDATE is necessary for the functionality. If it is not required, remove it to streamline the script.

## Tasks

1. Review the current generated query to understand the purpose of the second SELECT @ROWS_TO_UPDATE.
2. Identify all instances and test the query without the second SELECT @ROWS_TO_UPDATE to ensure it still functions correctly.
3. If the second select is not required, refactor the query to remove it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.