<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Garima Gupta on Medium]]></title>
        <description><![CDATA[Stories by Garima Gupta on Medium]]></description>
        <link>https://medium.com/@garima.gupta882?source=rss-d1aae2507c82------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zin1BvvIUXA_FlQUI6ru2A.jpeg</url>
            <title>Stories by Garima Gupta on Medium</title>
            <link>https://medium.com/@garima.gupta882?source=rss-d1aae2507c82------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:58:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@garima.gupta882/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Converting User-Defined Tables to Temporary Tables]]></title>
            <link>https://medium.com/@garima.gupta882/converting-user-defined-tables-to-temporary-tables-1c96a669bd0a?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c96a669bd0a</guid>
            <category><![CDATA[sql-tuning-in-sql-server]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Tue, 06 Oct 2026 18:12:20 GMT</pubDate>
            <atom:updated>2026-10-06T18:12:20.548Z</atom:updated>
            <content:encoded><![CDATA[<p>Problem — When dealing with large datasets, user-defined tables (UDTs) can cause performance issues. Converting UDTs to temporary tables can help improve performance, especially when the data volume is high. Temporary tables allow the creation of indexes, which can significantly enhance query performance.</p><pre>suppose you have some sp where you are accessing some data UDT which very huge data set like billing lines . than you can create temp table to insert that data and re use everytime that data is required.<br>temp table stored data in memory which makes it processing faster instead of copying from database directly.Just analyze are there any common joins among slect statements taking more time<br><br>Enable the profiler while testing to capture how much data temp variable is fetching from DB</pre><h4>Explanation of Performance Optimization:</h4><h4>Observing Performance:</h4><ul><li>Run the stored procedure and measure the execution time.</li><li>Compare this with a version of the stored procedure that directly queries the UDT without converting it to a temporary table.</li><li>You should observe faster execution with the temporary table due to indexing and query optimization.</li></ul><p><strong>Left Joins: </strong>Converting subqueries to left joins can improve query performance by reducing the number of records processed in the subquery. Left joins are more efficient and can significantly reduce query execution time.</p><p><strong>Filter Conditions: </strong>Relocating filter conditions from the WHERE clause to the ON clause can help in filtering data earlier in the query execution process. This technique reduces the number of records processed in subsequent joins, improving perform</p><pre>In SQL query processing, the logical order of execution for a JOIN condition, WHERE clause, and SELECT statement is as follows: the sequence is FROM/JOIN → WHERE → SELECT.</pre><ol><li><strong>FROM / JOIN:</strong> The database first determines the tables involved in the query (specified in the FROM clause) and how they should be combined if there are JOIN operations. This step creates the initial dataset that the rest of the query will work with.</li><li><strong>WHERE:</strong> Next, the WHERE clause is applied to filter the rows resulting from the FROM and JOIN operations. Only the rows that satisfy the conditions specified in the WHERE clause are passed on to the subsequent steps.</li><li><strong>SELECT:</strong> Finally, the SELECT statement determines which columns will be included in the final result set. Any expressions or calculations specified in the SELECT clause are also evaluated at this stage.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c96a669bd0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL query’s CPU time > its elapsed (wall-clock) time]]></title>
            <link>https://medium.com/@garima.gupta882/sql-querys-cpu-time-its-elapsed-wall-clock-time-b6a0999a7ef5?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6a0999a7ef5</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[sql-optimization]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Tue, 06 Oct 2026 18:09:51 GMT</pubDate>
            <atom:updated>2026-10-06T18:09:51.597Z</atom:updated>
            <content:encoded><![CDATA[<h4>Problem Statement</h4><p>The query in question was supposed to answer a simple question — “what unbilled work is sitting on this project?” — but it was touching roughly 4.7 million pages of data per run to answer it, when a well-tuned version of the same question should have needed around 50,000 pages. That’s about 94 times more work than necessary, and it showed up as a 5-to-6 second screen load with over 10 seconds of CPU burned per execution — CPU time nearly double the elapsed time, which is exactly the “threads fighting the problem and still losing” signal described above. All three patterns were present in the same query at once, which is common: performance problems rarely come alone, they compound.</p><h3>SQL Analysis</h3><p><strong>The diagnostic signal first.</strong> Before touching any fix, it’s worth teaching how you <em>know</em> something is wrong. If a query’s CPU time is higher than its elapsed (wall-clock) time, that tells you SQL Server threw multiple parallel threads at the problem and those threads collectively burned more CPU than a single thread would have taken in real time — and it still wasn’t fast. That’s a query fighting itself, not just a slow query. Pair that with logical reads (how many pages the engine had to touch) compared to what a well-indexed, correctly-filtered version of the same question should need, and you get a sense of how much wasted work is happening per execution, not just that it’s slow.</p><p><strong>Pattern one: the accidental cross join.</strong> This happens when a query needs a small, specific set of rows from a table — say, “the one row for configuration A and the one row for configuration B” — but instead of joining those rows on a key that ties them together, the table is listed twice in the FROM clause with no linking condition, or with a linking condition that isn’t restrictive enough. SQL Server has no way to know the two listings should correspond row-for-row, so it computes every combination of every row with every other row (a Cartesian product), and only afterward filters down to the combinations that matter. For a table with even a modest number of rows, that combinatorial explosion can produce orders of magnitude more intermediate rows than the query actually needs — and if this bad join is repeated across several branches of a larger query (like several UNIONed sub-queries), the explosion compounds each time. The fix is almost always one missing join condition: add the predicate that ties the two copies of the table back together on whatever natural key distinguishes “configuration A’s row” from “configuration B’s row” for the same real-world entity. It’s a one-line change with an outsized effect, because you’re not optimizing the join — you’re eliminating a join that should never have been a cross product in the first place.</p><p><strong>Pattern two: plan instability from heavy parameterization.</strong> SQL Server doesn’t compile a fresh query plan every time a query runs — it caches the plan from whoever happens to run it first, then reuses that plan for everyone else who calls the same query text, regardless of what parameter values they pass in. This is normally a good thing (compiling plans is expensive), but it breaks down when a query takes a very large number of input parameters covering many different filtering dimensions — different entities, time periods, statuses, and so on. The execution plan that’s efficient for one person’s combination of filters (say, a narrow slice of data) can be disastrously inefficient for someone else’s combination (say, a much broader slice), because the cached plan’s assumptions about row counts and selectivity no longer hold. The practical fix is to force a recompile for that specific query — telling the engine “don’t reuse a cached plan, work out the best plan for this exact set of parameter values, every time.” This costs a little extra compilation time per call but avoids the much larger cost of running the wrong plan against the wrong data shape. It’s the right trade-off specifically when a query has many parameters and wildly different usage patterns across users — not a default you’d reach for on every query.</p><p><strong>Pattern three: a lookup repeated many times with no index to support it.</strong> Some queries need to re-check a condition against a reference or security table for every row they’re evaluating — for example, “does this row belong to an organization the current user is allowed to see?” If that reference table has no index on the columns being checked, each one of those checks becomes a full scan of the entire table. Multiply a handful of scans per row by thousands of rows being evaluated, and you get tens of thousands of full table scans for what should be a handful of indexed lookups. The fix is a targeted non-clustered index covering exactly the columns used in that check, which turns each full scan into a near-instant index seek. This kind of index is usually safe to add without downtime, since creating it doesn’t require rewriting the table’s physical storage or taking it offline.</p><h3>Solution</h3><p>None of this required rewriting business logic. It took one missing join predicate, one query hint, and one index — three structural fixes, each addressing a different silent killer, together closing a 94x efficiency gap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6a0999a7ef5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving the Cache Hit Ratio is the way to cut latency.]]></title>
            <link>https://medium.com/@garima.gupta882/improving-the-cache-hit-ratio-is-the-way-to-cut-latency-224cfb8026b5?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/224cfb8026b5</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[performance-engineering]]></category>
            <category><![CDATA[performance-management]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 18:58:41 GMT</pubDate>
            <atom:updated>2026-09-18T18:58:41.421Z</atom:updated>
            <content:encoded><![CDATA[<p>Improving the Cache Hit Ratio is the way to cut latency.</p><p>Measure this if you are using Cache.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*v4lYbCmtmpT3hbwyXndlag.jpeg" /></figure><p>The Cache Hit Ratio measures how often requests are served from the cache rather than the primary store the primary store. (e.g., database, API, etc.).</p><p>Simply put, it tells you how well the cache performs.</p><p>The ratio is calculated by dividing the number of cache hits by the total number of cache lookups (hits and misses) and multiplying by 100 to get a percentage.</p><p>𝗧𝗵𝗲 𝗳𝗼𝗿𝗺𝘂𝗹𝗮 𝗶𝘀:</p><p>Cache Hit Ratio (%) = (Cache Hits / Total Lookups) x 100</p><p>𝗙𝗼𝗿 𝗰𝗼𝗻𝘁𝗲𝘅𝘁, 𝗹𝗲𝘁’𝘀 𝗰𝗼𝗻𝘀𝗶𝗱𝗲𝗿 𝗮 𝘀𝗶𝗺𝗽𝗹𝗲 𝗲𝘅𝗮𝗺𝗽𝗹𝗲:</p><p>• Your service receives 10 requests.</p><p>• The first request queries the cache, finds nothing (cache miss), queries the database, and then stores the result in the cache.</p><p>• The following 9 requests hit the cache and get served immediately (cache hits).</p><p>In this scenario, you have 9 cache hits out of 10 total lookups, resulting in a 90% cache hit ratio.</p><p>𝗪𝗵𝗶𝗹𝗲 𝘁𝗵𝗲𝗿𝗲’𝘀 𝗻𝗼 𝗼𝗻𝗲-𝘀𝗶𝘇𝗲-𝗳𝗶𝘁𝘀-𝗮𝗹𝗹 𝗻𝘂𝗺𝗯𝗲𝗿, 𝗵𝗲𝗿𝗲’𝘀 𝗮 𝗴𝗲𝗻𝗲𝗿𝗮𝗹 𝗴𝘂𝗶𝗱𝗲𝗹𝗶𝗻𝗲:</p><p>• For small to medium-scale services: Aim for a cache hit ratio between 90% and 95%.<br>• For large-scale systems handling millions of queries per second (QPS): Aim for 99% or higher.</p><p>𝟯 𝘄𝗮𝘆𝘀 𝘁𝗼 𝗕𝗼𝗼𝘀𝘁 𝗬𝗼𝘂𝗿 𝗖𝗮𝗰𝗵𝗲 𝗛𝗶𝘁 𝗥𝗮𝘁𝗶𝗼</p><p>• Pre-load popular cache entries during deployments or cold starts to avoid an initial spike in cache misses.</p><p>• Tune your time-to-live (TTL) value. Too short, and items expire quickly, causing misses. Too long, and you risk serving stale data.</p><p>• Make sure keys are unique but predictable to prevent missed cache entries.</p><p>𝗢𝗻𝗲 𝗳𝗶𝗻𝗮𝗹 𝘁𝗵𝗼𝘂𝗴𝗵𝘁:</p><p>A high cache hit ratio is great, but not at the expense of serving outdated information.</p><p>You need a balance between cache effectiveness and data freshness.</p><p>You can’t improve what you don’t measure.</p><p>Do you know how good your Cache is?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=224cfb8026b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fan Out and Fan In approach]]></title>
            <link>https://medium.com/@garima.gupta882/fan-out-and-fan-in-approach-790387d92987?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/790387d92987</guid>
            <category><![CDATA[fan-out-fan-in]]></category>
            <category><![CDATA[performance-management]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[load-testing]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Fri, 04 Sep 2026 13:40:57 GMT</pubDate>
            <atom:updated>2026-09-04T13:40:57.294Z</atom:updated>
            <content:encoded><![CDATA[<p>Batch processing performance optimization</p><h4>Problem Statement —</h4><p>While executing Bill batch for ~500K and ~1000 , getting Internal server error from client side.</p><p>Error that we are getting on PUTBlob is due to timeout in file upload. The size of file we upload in of size 180MB whereas in alpha file upload is of maximum size 75 MB.<br>Below mentioned is app insight trace for timeout at upload</p><p>was that Bill orchestrator function is calling Normalize activity function only once and that activity function is doing all the job of calling People APIs, Chunking, and File upload that too in foreach loop for set of caregivers. Due to this number of threads are increasing and we don’t have control of them causing spikes and ultimately timeouts for larger files size. Ideally, activity function should perform singular operation and if required, create another activity function for other task.</p><p><strong>Solution: </strong>Implement Fan out- fan in approach in Bill orchestrator. Chunk the 77k users into say size of 1000 users each. Call Normalize activity function for each smaller chunk created and ultimately upload file using BlockBlobClient. Please refer the attached Doc for similar implementation in Billing Orchestrator.</p><p>Analysis -</p><p>They were also sequentially uploading data to blob storage for each caregiver (batching caregiver wise) in one of the Normalise activity func which took 4min for 6500 caregivers (in 23K batch ; we need to test 600K batch with 72K users ). Onsite team said they will look into increasing parallelism here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=790387d92987" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[To collect a memory dump from a .NET Core application running on Kubernetes]]></title>
            <link>https://medium.com/@garima.gupta882/to-collect-a-memory-dump-from-a-net-core-application-running-on-kubernetes-70607d8d2698?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/70607d8d2698</guid>
            <category><![CDATA[performance-testing]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Fri, 04 Sep 2026 13:35:52 GMT</pubDate>
            <atom:updated>2026-09-04T13:35:52.010Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern microservices architectures, applications often run within Kubernetes clusters, making debugging a complex task.One effective method for diagnosing issues in .NET Core applications is through memory dump analysis. A memory dump captures the application’s memory at a specific point, offering insights into potential problems, bottlenecks, or crashes. This guide outlines the steps to collect a memory dump from a .NET Core application running on Kubernetes.</p><p><strong>Prerequisites:</strong></p><ul><li>Ensure kubectl is installed on your local machine. If not, install it using the appropriate method for your operating system.</li></ul><p><strong>Step 1: Identify the Target Pod</strong></p><p>Begin by identifying the pod running your .NET Core application. Use a label selector to list the relevant pods in your namespace:</p><pre>kubectl get pods --selector=app.kubernetes.io/instance=YOUR_APP_NAME --namespace YOUR_NAMESPACE_NAME -o=name --kubeconfig &quot;path_to_kubeconfig.yaml&quot;<br>```<br>- Replace `YOUR_APP_NAME` with your application&#39;s name.<br>- Replace `YOUR_NAMESPACE_NAME` with your Kubernetes namespace.<br>- The `--kubeconfig` parameter specifies the path to your Kubernetes configuration file.</pre><p><strong>Step 2: Access the Pod</strong></p><p>Once you’ve identified the target pod, access it using kubectl exec:</p><pre>kubectl exec -it &quot;pod/YOUR_POD_NAME&quot; --kubeconfig &quot;path_to_kubeconfig.yaml&quot; --namespace YOUR_NAMESPACE_NAME -- sh</pre><p>Replace YOUR_POD_NAME with the name of your pod.</p><p>Step 3: Download and Prepare dotnet-dump</p><p>Inside the pod, navigate to the /tmp directory to ensure you have write permissions:</p><pre>cd /tmp</pre><p>Download the dotnet-dump tool:</p><pre>curl -L -o dotnet-dump https://aka.ms/dotnet-dump/linux-x64</pre><p>Grant execution permissions to the tool:</p><pre>chmod 777 ./dotnet-dump</pre><p>Set the extraction directory for the tool:</p><pre>export DOTNET_BUNDLE_EXTRACT_BASE_DIR=&quot;/tmp/bundle_extract&quot;</pre><p>Step 4: Collect the Memory Dump</p><p>Identify the process ID (PID) of your .NET Core application. You can list all running processes to find the correct PID. Once identified, collect the memory dump:</p><pre>./dotnet-dump collect -p YOUR_PROCESS_ID</pre><ul><li>Replace YOUR_PROCESS_ID with the PID of your application.</li></ul><p>The tool will generate a memory dump file named core_&lt;timestamp&gt; in the /tmp directory.</p><p><strong>Step 5: Compress the Memory Dump</strong></p><p>Compress the memory dump to facilitate easier transfer:</p><pre>gzip core_&lt;timestamp&gt;</pre><p><strong>Step 6: Transfer the Memory Dump to Your Local Machine</strong></p><p>Exit the pod’s shell:</p><pre>exit</pre><p>Use kubectl cp to copy the compressed memory dump from the pod to your local machine:</p><pre>kubectl cp &quot;YOUR_POD_NAME:/tmp/core_&lt;timestamp&gt;.gz&quot; ./core_&lt;timestamp&gt;.gz --kubeconfig &quot;path_to_kubeconfig.yaml&quot; --namespace YOUR_NAMESPACE_NAME</pre><p><strong>Step 7: Decompress the Memory Dump</strong></p><p>On your local machine, decompress the memory dump:</p><pre>gunzip core_&lt;timestamp&gt;.gz</pre><p>Step 8: Analyze the Memory Dump</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70607d8d2698" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG Chatbot Performance Tuning]]></title>
            <link>https://medium.com/@garima.gupta882/rag-chatbot-performance-tuning-2dc62c9e6a20?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dc62c9e6a20</guid>
            <category><![CDATA[rag-optimization]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[fine-tuning]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Mon, 29 Jun 2026 13:46:10 GMT</pubDate>
            <atom:updated>2026-06-29T13:46:10.466Z</atom:updated>
            <content:encoded><![CDATA[<h4>Problem Statement — Your RAG chatbot works perfectly today. Tomorrow , the company uploads 10,000 new documents.</h4><p>How do you make the chatbot use the new knowledge withoute rebuilding the entire vector database?</p><h4>Wrong solution — Re-embed everything.</h4><h4>Correct Solution — <br> Incremental Indexing</h4><p>Only process the newly uploaded or modified documents.</p><p>Generate embeddings for those documents and add them to the existing vector database.</p><h4>Version your documents</h4><p>Every document should have:</p><p>Version , Upload timestamp , Metadata</p><p>This makes updates and rollbacks easier.</p><h4>Delete or Archive Stale embeddings</h4><p>If a document is updated , don&#39;t keep outdated embeddings in your index.</p><p>Mark them inactive or remove them to avoid retrieving old information.</p><h4>Asynchronous Ingestion</h4><p>Never block users while indexing.</p><p>Use a queue so documents are parsed,chunked,embedded and indexed in the background.</p><h4>Refresh Metadata</h4><p>Update filters like:</p><p>Department , Category , Date , Document Type</p><p>Good metadata often improves retrieval more than changing the embedding model.</p><p>A production RAG is never “finished”.</p><p>it’s continuously ingesting, indexing and evolving.</p><p>The real challenge is not building the chatbot.</p><p>Its keeping its knowledge up to date without Downtime.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dc62c9e6a20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KQL — Kusto monitoring queries]]></title>
            <link>https://medium.com/@garima.gupta882/kql-kusto-monitoring-queries-05789c822a92?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/05789c822a92</guid>
            <category><![CDATA[logging-and-monitoring]]></category>
            <category><![CDATA[kql]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Tue, 23 Jun 2026 09:56:06 GMT</pubDate>
            <atom:updated>2026-06-23T09:56:06.897Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>KQL (Kusto Query Language)</strong> is a powerful, read-only query language created by Microsoft. It is designed specifically to process massive volumes of streaming data and is the primary language used to query telemetry, logs, and metrics in services like Azure Monitor, Azure Data Explorer (ADX), Application Insights, and Microsoft Sentinel.</p><p>A typical KQL monitoring query starts with a table name (like requests, exceptions, or traces) and applies a sequence of operators.</p><p>Here is a practical example of a monitoring query designed to identify performance bottlenecks — specifically, finding the top 5 slowest API operations over the last 24 hours:</p><pre>// 1. Define the data source<br>AppRequests<br>// 2. Filter the time range (highly optimized in KQL)<br>| where TimeGenerated &gt; ago(24h)<br>// 3. Filter for successful requests only<br>| where Success == true<br>// 4. Aggregate the data<br>| summarize AverageDuration = avg(DurationMs), TotalRequests = count() by OperationName<br>// 5. Filter out noise (e.g., endpoints rarely hit)<br>| where TotalRequests &gt; 100<br>// 6. Sort and limit the results<br>| top 5 by AverageDuration desc</pre><h4>Response Time Calculations</h4><pre>Basic Aggregations<br>// Count events by time buckets (1 hour bins)<br>Requests<br>| where Timestamp &gt; ago(7d)<br>| summarize Count=count() by bin(Timestamp, 1h)<br>| render timechart<br><br>// Multiple aggregations at once<br>Requests<br>| where Timestamp &gt; ago(24h)<br>| summarize <br>    TotalRequests = count(),<br>    AvgLatency = avg(Duration),<br>    P50 = percentile(Duration, 50),<br>    P95 = percentile(Duration, 95),<br>    P99 = percentile(Duration, 99),<br>    ErrorCount = countif(StatusCode &gt;= 500)<br>    by bin(Timestamp, 5m)</pre><h3>Time-Series Functions</h3><pre>// Detect anomalies using series_decompose_anomalies<br>Requests<br>| where Timestamp &gt; ago(7d)<br>| summarize Count=count() by bin(Timestamp, 1h)<br>| summarize Timestamps=make_list(Timestamp), Counts=make_list(Count)<br>| extend (anomalies, score, baseline) = series_decompose_anomalies(Counts)<br>| mv-expand Timestamps, Counts, anomalies, score, baseline<br>| where anomalies != 0<br><br>// Fill gaps in time series<br>Requests<br>| where Timestamp &gt; ago(1d)<br>| summarize Count=count() by bin(Timestamp, 5m)<br>| make-series Count=sum(Count) default=0 on Timestamp step 5m</pre><h3>Trend Analysis</h3><pre>// Compare current hour vs same hour yesterday<br>let current = Requests | where Timestamp &gt; ago(1h) | summarize CurrentCount=count();<br>let yesterday = Requests | where Timestamp between (ago(25h) .. ago(24h)) | summarize YesterdayCount=count();<br>current | extend YesterdayCount = toscalar(yesterday | project YesterdayCount)<br>| extend ChangePercent = round((CurrentCount - YesterdayCount) * 100.0 / YesterdayCount, 2)<br><br>// Week-over-week comparison<br>Requests<br>| where Timestamp &gt; ago(14d)<br>| extend Week = iff(Timestamp &gt; ago(7d), &quot;This Week&quot;, &quot;Last Week&quot;)<br>| summarize Count=count() by Week, bin(Timestamp, 1h) % 7d<br>| render timechart</pre><h3>Sliding Window Analysis</h3><pre>// Rolling average (moving average over 1 hour window)<br>Requests<br>| where Timestamp &gt; ago(24h)<br>| summarize Count=count() by bin(Timestamp, 5m)<br>| order by Timestamp asc<br>| extend RollingAvg = avg(Count) over (rows between 11 preceding and current row)<br>| render timechart<br><br>// Rate of change<br>Requests<br>| where Timestamp &gt; ago(6h)<br>| summarize Count=count() by bin(Timestamp, 5m)<br>| order by Timestamp asc<br>| extend PrevCount = prev(Count), RateChange = (Count - prev(Count)) * 100.0 / prev(Count)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05789c822a92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Deadlock Optimizations]]></title>
            <link>https://medium.com/@garima.gupta882/sql-deadlock-optimizations-470c9ac00f6e?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/470c9ac00f6e</guid>
            <category><![CDATA[db-deadlock]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Thu, 04 Jun 2026 07:31:08 GMT</pubDate>
            <atom:updated>2026-06-04T07:31:08.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hIfFv802AXVMi0I0PBP3Lw.png" /><figcaption>Deadlock</figcaption></figure><h4>DMV Queries to execute in SQL DB to identify deadlocks</h4><pre>- step 1 - use MASTERSELECT * FROM sys.event_logWHERE event_type= &#39;deadlock&#39;and start_time&gt; &#39;2023–02–08 00:00:26.5233333&#39;and start_time&lt; &#39;2023–07–10 20:32:25.4600000&#39;order by start_timedesc</pre><pre>- step 2<br> - run in master DB - you can get a trend of what specific queries and objects are causing deadlocking with in your databases. - restrict the output by specifying the datetime range;WITH CTE AS (SELECT CAST(event_dataAS XML) AS [target_data_XML] FROM sys.fn_xe_telemetry_blob_target_read_file(&#39;dl&#39;, null, null, null))SELECT [db_name], [query_text], [wait_resource], COUNT(*) as [number_of_deadlocks] FROM (SELECT LTRIM(RTRIM(Replace(Replace(c.value(&#39;.&#39;, &#39;nvarchar(250)&#39;),CHAR(10),&#39; &#39;),CHAR(13),&#39; &#39;))) as query_text,D.value(&#39;@waitresource&#39;, &#39;nvarchar(250)&#39;) AS [wait_resource],target_data_XML.query(&#39;/event/data[@name=&#39;&#39;database_name&#39;&#39;]/value&#39;).value(&#39;(/value)[1]&#39;, &#39;nvarchar(250)&#39;) AS [db_name]from CTE CROSS APPLY target_data_XML.nodes(&#39;(/event/data/value/deadlock/process-list/process/inputbuf)&#39;) AS T(C)CROSS APPLY target_data_XML.nodes(&#39;(/event/data/value/deadlock/process-list/process)&#39;) AS Q(D)where CTE.target_data_XML.value(&#39;(/event/@timestamp)[1]&#39;, &#39;DateTime2&#39;) &gt;= &#39;2023–05–26 15:49:41.4266667&#39;and target_data_XML.value(&#39;(/event/@timestamp)[1]&#39;, &#39;DateTime2&#39;) &lt;=&#39;2023–05–26 15:49:46.4633333&#39;) deadlockGROUP BY [query_text], [wait_resource], [db_name]ORDER BY [number_of_deadlocks] DESC</pre><pre>- step 3<br> - mention values for 64 and 65 line from above query - Query to get the XML , copy the XML in notepad and save as .XDL file and open in SSMS to get the dealockgraph details;WITH CTE AS (SELECT CAST(event_dataAS XML) AS [target_data_XML] FROM sys.fn_xe_telemetry_blob_target_read_file(&#39;dl&#39;, null, null, null))SELECT [db_name], [wait_resource], [deadlock_xml] FROM (SELECT target_data_XML.query(&#39;/event/data[@name=&#39;&#39;database_name&#39;&#39;]/value&#39;).value(&#39;(/value)[1]&#39;, &#39;nvarchar(250)&#39;) AS [db_name],waitresource_node.value(&#39;@waitresource&#39;, &#39;nvarchar(250)&#39;) AS [wait_resource],deadlock_node.query(&#39;.&#39;) as [deadlock_xml]FROM CTE CROSS APPLY target_data_XML.nodes(&#39;(/event/data/value/deadlock)&#39;) AS T(deadlock_node)CROSS APPLY target_data_XML.nodes(&#39;(/event/data/value/deadlock/process-list/process)&#39;) AS U(waitresource_node)where CTE.target_data_XML.value(&#39;(/event/@timestamp)[1]&#39;, &#39;DateTime2&#39;) &gt;= &#39;2023–05–26 15:49:41.4266667&#39;and target_data_XML.value(&#39;(/event/@timestamp)[1]&#39;, &#39;DateTime2&#39;) &lt;= &#39;2023–05–26 15:49:46.4633333&#39;<br><br>) deadlockWHERE [db_name] = &#39;U2Billing_cdwa&#39;AND [wait_resource] = &#39;PAGE: 22:1:19099186&#39;</pre><p>Save Query text of deadlock query as .xdlfile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZqH0uVwAJm6bfkeloU9XQ.png" /></figure><h4>Fix</h4><p>Made changes to Sp##### in ## DB . Split the merge statement for#### table into 3 steps : Delete, Update and Insert to resolve deadlock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRBQ-pfXd_aSUjLlsn-qdg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470c9ac00f6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL DB best practices cheatsheet]]></title>
            <link>https://medium.com/@garima.gupta882/db-tips-cbd3ceefeeb8?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbd3ceefeeb8</guid>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Thu, 04 Jun 2026 07:24:51 GMT</pubDate>
            <atom:updated>2026-10-06T18:15:27.899Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Use Query Store to identify which specific queries inside a stored procedure are the costly ones — it gives you the query ID and execution plan for every query within the SP, so you can focus tuning effort on the few queries actually driving the cost rather than the whole procedure.</li><li>Make sure indexes cover the columns used in joins and filters, not just the columns being selected.</li><li>To avoid parameter sniffing, declare local variables inside the stored procedure, assign the incoming parameters to them immediately, and use those local variables throughout the rest of the code instead of referencing the parameters directly.</li><li>Break large, monolithic queries into several smaller queries — this changes the execution plan significantly and often avoids the inefficiencies that build up in one giant query.</li><li>Prefer temp tables (#table) over table variables (@table) for anything nontrivial — in particular, INSERT INTO @table1 executes on a single worker thread (effectively MAXDOP 1), while SELECT … INTO #table1 can run in parallel.</li><li>Reduce the number of joins in a query wherever possible.</li><li>Move filtering conditions from the WHERE clause into the JOIN clause so the data is filtered as early as possible, keeping the working result set small throughout the query.</li><li>When a join exists purely to check whether a related row exists — and no columns are actually being selected from the joined table — use an EXISTS block instead of a JOIN.</li><li>The choice between EXISTS and JOIN should also depend on indexing: if the columns used in the condition are already covered by an index, a JOIN can outperform EXISTS, so test both rather than assuming one is always faster.</li><li>If a temp table holds a significant amount of data (roughly more than 100,000 records) and is referenced in multiple places in the code, create an index on the temp table covering the columns used to join it elsewhere.</li><li>Tune MAXDOP based on what Query Store’s wait-time and wait-type data shows for a given query — if a query is spending significant time on the “Parallelism” wait type, consider lowering MAXDOP for that specific query.</li><li>If a stored procedure only reads data and never modifies it, consider routing it to a read replica (available on the Premier tier in Azure SQL DB) to offload read traffic from the primary.</li><li>Use Query Store to examine reads, writes, and memory consumption for a query, and rewrite the query specifically to reduce those reads and writes.</li><li>If a single query has multiple execution plans in use, consider forcing a specific plan or forcing use of a specific index to get consistent, predictable performance.</li><li>When you need columns from a right-hand table corresponding to a row in a left-hand table, prefer a plain INNER or LEFT JOIN; reserve CROSS APPLY or OUTER APPLY for cases where you need the top-1 row or an aggregated value from the right-hand table per row of the left-hand table — CROSS APPLY and OUTER APPLY are generally preferable to a JOIN combined with a subquery in those scenarios.</li><li>Use window functions such as FIRST_VALUE() and LAST_VALUE() instead of correlated subqueries where applicable.</li><li>Be cautious with CTEs in Azure SQL — they don’t reliably favor performance there; they’re fine when the CTE is operating over a small dataset, but can hurt performance on larger ones.</li><li>Review the execution plan for costly operators, and confirm the query is actually using the indexes you expect it to use rather than falling back to scans.</li><li>Keep statistics current — enable auto-update statistics and the ASYNC_STATS_UPDATE_WAIT_AT_LOW_PRIORITY setting for the database so stats refresh without blocking queries.</li><li>A lower MAXDOP value generally benefits UPDATE and DELETE statements.</li><li>Make sure foreign key columns are covered by indexes.</li><li>Avoid giving a stored procedure too many parameters — a large parameter count can lead to an overly complex execution plan or to plan instability across multiple executions.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbd3ceefeeb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Query Execution Order]]></title>
            <link>https://medium.com/@garima.gupta882/sql-query-execution-order-856cdd2e875a?source=rss-d1aae2507c82------2</link>
            <guid isPermaLink="false">https://medium.com/p/856cdd2e875a</guid>
            <category><![CDATA[sql-query-optimization]]></category>
            <category><![CDATA[order-of-execution]]></category>
            <category><![CDATA[query-optimization]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Garima Gupta]]></dc:creator>
            <pubDate>Fri, 29 May 2026 16:15:24 GMT</pubDate>
            <atom:updated>2026-05-29T16:15:24.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mhSHlXdfT02jVf1t7gQj5A.gif" /></figure><p>We generally writes SQL in order :</p><pre>SELECT → FROM → WHERE</pre><p>whereas SQL actually run like in order :</p><pre>FROM → WHERE → SELECT</pre><p>Let that sink in</p><p>So the order you write SQL is NOT the order it executes. And once you understand this — everything changes.</p><p>The Real Order :</p><p><strong>Step 1 </strong>— FROM / JOIN / ON</p><p>Table get joins first.</p><p><strong>Step 2 — </strong>WHERE</p><p>Rows are filtered.</p><p><strong>Step 3 — </strong>GROUP BY</p><p>Rows are bucketed.</p><p><strong>Step 4 — </strong>HAVING</p><p>Groups are filtered.</p><p><strong>Step 5— </strong>SELECT DISTINCT</p><p>Finally — your columns are picked.</p><p><strong>STEP 6 — </strong>ORDER BY</p><p>Results are sorted.</p><p><strong>STEP 7—</strong>LIMIT</p><p>Only what’s needed is returned.</p><p>It’s the secret behind every fast query</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=856cdd2e875a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>