March 31, 2023
Microsoft Security

Microsoft 365 Defender: Optimizing KQL queries

Microsoft Security logo

This tutorial demonstrates how to optimize Kusto Query Language (KQL) for Advanced Hunting in Microsoft 365 Defender so queries run faster and avoid timeouts—especially at enterprise scale. It begins with an intentionally slow join between IdentityLogonEvents and IdentityInfo, then shows how to use the execution-time and resource-usage indicator (low/medium/high) plus count to spot overly broad queries. The core guidance is to filter early—especially with time filters, since KQL is highly optimized for them—using conditions like “greater than 1 hour ago” or a bounded window with between. It then covers practical operator choices: prefer has over contains when you’re matching full tokens, use case-sensitive operators where possible (has_cs, equals vs equals~), and treat joins with care by filtering the left table first, placing the smaller table on the left, and understanding join behavior—default innerunique can de-duplicate and hide useful duplicates, so an inner join may be safer when duplicate join keys matter (like multiple attachments).

We produced this as a performance-minded training clip—designed to teach a repeatable mental model, not just a bag of tricks. The pacing intentionally shows the “before” pain, then the “after” improvement, with clean callouts for what changed and why it helped. The result is a tutorial viewers can apply immediately to their own hunts—faster results, fewer resource spikes, and a smoother path to meaningful findings. Final delivery includes closed captions, audio description, and thumbnails.

Microsoft Security logo
Share this video