Azure / Azure/data-api-builder
Evaluate potential redundancies in our generated SQL query
- Vorherrschende Sprache
- C#
- Sterne
- 1.5k
- Forks
- 370
- Ø Merge
- 3 T. 22 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Es werden keine Dateien oder Tests genannt. Beginne damit, den Generator für UPDATE/DELETE-Abfragen zu finden und das zugehörige Issue #2412 zu prüfen; identifiziere jede Verwendung des zweiten SELECT und führe anschließend die relevanten Abfragetests oder Datenbankprüfungen aus. Erledigt ist die Aufgabe, wenn das SELECT nur dann entfernt wird, wenn die Funktionalität und die zurückgegebenen Ergebnisse weiterhin korrekt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp, sql
- Bereich
- backend, databases
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100