Statisk analys av LINQ-frågor för prestandaoptimering : En indexmedvetet metod för kompileringstidoptimering av databasfrågor

Westberg-Bladh, Alexander · Diva portal (Dalarna University Library) · 2025

Language integrated query (LINQ) is a powerful extension to C# that enables integration of database queries into the programming language. However, not all LINQ queries can be translated to SQL, and the programmer is not always aware of the performance of the queries against a database, particularly when using indexes. This thesis addresses these challenges through theoretical and practical contributions. We develop a novel object-based core language based on C# , incorporating query capabilities similar to LINQ, and present a type-and-effect system for analyzing query expressions. The core language has two features, it can guarantee that the query expressions can be translated into SQL and that queries that do not utilize any database search index can be detected. The work builds on existing research in the area of language integration. After LINQ was created, a method to guarantee translation to SQL was developed. We extend this work to include the concept of indexes and how they can be utilized in query expressions. Based on the core language, we have created a C# analyzer that can detect some problematic queries. The analyzer can be integrated into an existing build pipline and will generate compiler errors and warnings if problematic queries are found. The analyzer was validated using a set of example quries as well as running on Challengermode’s codebase. The analyzer successfully identified several performance-critical issues in production code, including 11 non-indexed queries and 4 potentially problematic large queries. This shows that this type of analyzer can give insight into performance issues before they are discovered in production. This thesis has shown that a type and effect system can be used to detect if an object-based language with query capabilities similar to LINQ can be translated to SQL and if it can be translated to SQL it can be detected if the query utilizes any database search index.

Read the paper · More papers on PaperTik