{"id":3134,"date":"2024-06-07T14:13:30","date_gmt":"2024-06-07T17:13:30","guid":{"rendered":"https:\/\/powertuning.com.br\/?p=3134"},"modified":"2024-06-07T14:20:43","modified_gmt":"2024-06-07T17:20:43","slug":"azure-sql-copilot-sera-que-ele-consegue-analisar-uma-query-e-sugerir-melhorias","status":"publish","type":"post","link":"https:\/\/powertuning.com.br\/blog\/azure-sql-copilot-sera-que-ele-consegue-analisar-uma-query-e-sugerir-melhorias\/","title":{"rendered":"Azure SQL Copilot \u2022 Ser\u00e1 que ele consegue analisar uma query e sugerir melhorias?"},"content":{"rendered":"<p>Fala Pessoal,<\/p>\n<p>Seguimos aqui nos testes e feedbacks do SQL Copilot para o time de produto.<\/p>\n<p>Dessa vez vou mostrar se ele consegue analisar uma query, que provavelmente ser\u00e1 uma das coisas que os clientes mais devem usar nele, principalmente quem n\u00e3o tem um DBA interno.<\/p>\n<p>Criei uma tabela de teste e inseri alguns registros:<\/p>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums\" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-8\">8<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-9\">9<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-10\">10<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-11\">11<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-12\">12<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-13\">13<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-14\">14<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-15\">15<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-16\">16<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-17\">17<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-18\">18<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-19\">19<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-20\">20<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-21\">21<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e61480538594368-22\">22<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-1\" class=\"crayon-line\"><span class=\"crayon-k\">CREATE<\/span> <span class=\"crayon-k\">TABLE<\/span> <span class=\"crayon-e\">Client<\/span><span class=\"crayon-sy\">(<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-i\">Id_Client<\/span> <span class=\"crayon-k\">INT<\/span> <span class=\"crayon-k\">IDENTITY<\/span><span class=\"crayon-sy\">,<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-3\" class=\"crayon-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Name<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-k\">VARCHAR<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-cn\">500<\/span><span class=\"crayon-sy\">)<\/span><span class=\"crayon-sy\">,<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-i\">BirtDate<\/span> <span class=\"crayon-k\">DATE<\/span><span class=\"crayon-sy\">,<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-5\" class=\"crayon-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Address<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-k\">VARCHAR<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-cn\">4000<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-6\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-7\" class=\"crayon-line\"><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-8\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-k\">INSERT<\/span> <span class=\"crayon-k\">INTO<\/span> <span class=\"crayon-e\">Client <\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Name<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-i\">BirtDate<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Address<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-9\" class=\"crayon-line\"><span class=\"crayon-k\">SELECT<\/span> <span class=\"crayon-s\">&#8216;Fabricio Lima good soccer player&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8216;19850611&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-e\">REPLICATE<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-s\">&#8216;good&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-cn\">1000<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-10\" class=\"crayon-line crayon-striped-line\"><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-11\" class=\"crayon-line\"><span class=\"crayon-k\">INSERT<\/span> <span class=\"crayon-k\">INTO<\/span> <span class=\"crayon-e\">Client <\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Name<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-i\">BirtDate<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Address<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-12\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-k\">SELECT<\/span> <span class=\"crayon-s\">&#8216;Fabiano Amorim bad soccer player&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8216;19680711&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-e\">REPLICATE<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-s\">&#8216;bad&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-cn\">1300<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-13\" class=\"crayon-line\"><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-14\" class=\"crayon-line crayon-striped-line\"><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-15\" class=\"crayon-line\"><span class=\"crayon-k\">INSERT<\/span> <span class=\"crayon-k\">INTO<\/span> <span class=\"crayon-e\">Client <\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Name<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-i\">BirtDate<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Address<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-16\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-k\">SELECT<\/span> <span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Name<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-i\">BirtDate<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Address<\/span><span class=\"crayon-sy\">]<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-17\" class=\"crayon-line\"><span class=\"crayon-k\">FROM<\/span> <span class=\"crayon-i\">Client<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-18\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-i\">GO<\/span> <span class=\"crayon-cn\">15<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-19\" class=\"crayon-line\"><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-20\" class=\"crayon-line crayon-striped-line\"><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-21\" class=\"crayon-line\"><span class=\"crayon-k\">INSERT<\/span> <span class=\"crayon-k\">INTO<\/span> <span class=\"crayon-e\">Client <\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Name<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-i\">BirtDate<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-i\">Address<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e61480538594368-22\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-k\">SELECT<\/span> <span class=\"crayon-s\">&#8216;Joe Sack good SQL Server player&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8216;19800711&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-e\">REPLICATE<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-s\">&#8216;good&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-cn\">1000<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Vamos trabalhar com uma query bem simples para facilitar o aprendizado:<\/p>\n<div id=\"urvanov-syntax-highlighter-6663267e6148a559351372\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums\" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e6148a559351372-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e6148a559351372-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e6148a559351372-3\">3<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-6663267e6148a559351372-1\" class=\"crayon-line\"><span class=\"crayon-e\">SELECT <\/span><span class=\"crayon-e\">DISTINCT <\/span><span class=\"crayon-e\">Name<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e6148a559351372-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">FROM <\/span><span class=\"crayon-e\">Client<\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e6148a559351372-3\" class=\"crayon-line\"><span class=\"crayon-e\">WHERE <\/span><span class=\"crayon-v\">Name<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-s\">&#8216;Joe Sack good SQL Server player&#8217;<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Ao rodar essa query no SSMS o SQL Server identifica um missed index e j\u00e1 nos sugere criar um \u00edndice na coluna Name.<\/p>\n<p>Vamos ver se o Copilot tamb\u00e9m nos sugere isso?<\/p>\n<p>Ele demora uns 40 segundos para responder e mostra essas mensagens enquanto processa:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19591 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-300x199.jpg\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" srcset=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-300x199.jpg 300w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-410x272.jpg 410w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-100x66.jpg 100w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-275x183.jpg 275w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-20x13.jpg 20w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301-272x182.jpg 272w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-301.jpg 542w\" alt=\"\" width=\"384\" height=\"255\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Mandei ele melhorar uma query que faltava um \u00edndice e ele realmente achou o missed index igual encontramos l\u00e1 no SSMS:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19592 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-300x297.jpg\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" srcset=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-300x297.jpg 300w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-150x150.jpg 150w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-410x406.jpg 410w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-100x99.jpg 100w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-275x272.jpg 275w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302-20x20.jpg 20w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-302.jpg 539w\" alt=\"\" width=\"404\" height=\"400\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Resposta completa do Copilot:<\/p>\n<div class=\"ac-textBlock\">\n<p><em>\u201cBased on the analysis of your query, I found a missing index recommendation that could potentially improve the performance of your query. Here are the details:<\/em><\/p>\n<ul>\n<li><em>The query with the hash\u00a0<code>0xD770ACA80BEFB236<\/code>\u00a0could benefit from an index on the\u00a0<code>Name<\/code>\u00a0column of the\u00a0<code>Client<\/code>\u00a0table. The suggested index creation statement is as follows:<\/em><\/li>\n<\/ul>\n<div id=\"urvanov-syntax-highlighter-6663267e6148c270218152\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums\" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e6148c270218152-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-6663267e6148c270218152-1\" class=\"crayon-line\"><span class=\"crayon-e\">CREATE <\/span><span class=\"crayon-e\">NONCLUSTERED <\/span><span class=\"crayon-i\">INDEX<\/span> <span class=\"crayon-sy\">[<\/span><span class=\"crayon-v\">NCI_Client_Name_5<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-i\">ON<\/span> <span class=\"crayon-sy\">[<\/span><span class=\"crayon-v\">CopilotSQL<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-v\">dbo<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-v\">Client<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-v\">Name<\/span><span class=\"crayon-sy\">]<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-e\">WITH<\/span> <span class=\"crayon-sy\">(<\/span><span class=\"crayon-v\">ONLINE<\/span><span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">ON<\/span><span class=\"crayon-sy\">,<\/span> <span class=\"crayon-v\">RESUMABLE<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-v\">ON<\/span><span class=\"crayon-sy\">)<\/span><span class=\"crayon-sy\">;<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><em>This index could potentially improve the performance of your query by 9,924.00%. Please note that this is an estimation and the actual benefit may vary. You should test this index in a non-production environment before implementing it in production.<\/em><\/p>\n<\/div>\n<div class=\"ac-textBlock\">\n<p><em>Regarding anti-pattern queries, I didn\u2019t find any in your workload. Azure SQL\u2019s internal telemetry did not flag any of your queries as containing an antipattern. However, there still may be other types of antipatterns in your queries not detected by the telemetry.<\/em><\/p>\n<p><em>Please continue with the following troubleshooting steps:<\/em><\/p>\n<ul>\n<li><em>Identify recent changes in database workload.<\/em><\/li>\n<\/ul>\n<p><em>For more information on identifying and adding missing indexes, you can refer to this\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/azure-sql\/database\/performance-guidance?view=azuresql#identifying-and-adding-missing-indexes\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">guide<\/a>.<\/em><\/p>\n<p><em>For more information on tuning nonclustered missing index suggestions, you can refer to this\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/indexes\/tune-nonclustered-missing-index-suggestions?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">guide<\/a>.<\/em><\/p>\n<p><em>For more information on performance problems due to antipattern queries, you can refer to this\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/techcommunity.microsoft.com\/t5\/azure-sql-blog\/watch-out-for-performance-problems-due-to-antipattern-queries-in\/ba-p\/3733386\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">blog post<\/a>.<\/em><\/p>\n<p><em>Click\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/sandbox-4.reactblade.portal.azure.net\/React\/Index?reactView=true&amp;retryCount=0&amp;l=en.pt-br&amp;trustedAuthority=https:\/\/portal.azure.com&amp;contentHash=c2Mxl89G2hBx&amp;reactIndex=0&amp;sessionId=f06fad87f3244b18b2a2e9d028834177#view\/SqlAzureExtension\/QueryEditorBlade\/resourceId\/%2Fsubscriptions%2Ff9056425-c4dc-4acd-9a22-3cd547f0e4d3%2FresourceGroups%2FCopilotSQL%2Fproviders%2FMicrosoft.Sql%2Fservers%2Fcopilotsqlbrazil%2Fdatabases%2FCopilotSQL\/queryText\/WITH%20query_missing_index%20AS%20(%20%0D%0A%20%20SELECT%20%0D%0A%20%20%20%20qsq.query_id%2C%20%0D%0A%20%20%20%20qsp.query_plan_hash%2C%20%0D%0A%20%20%20%20qsq.query_hash%2C%20%0D%0A%20%20%20%20qsqt.query_sql_text%20AS%20query_text%20%0D%0A%20%20FROM%20sys.query_store_query%20AS%20qsq%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_plan%20AS%20qsp%20%0D%0A%20%20%20%20ON%20qsq.query_id%20%3D%20qsp.query_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats%20AS%20qrs%20%0D%0A%20%20%20%20ON%20qsp.plan_id%20%3D%20qrs.plan_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats_interval%20AS%20qsrsi%20%0D%0A%20%20%20%20ON%20qrs.runtime_stats_interval_id%20%3D%20qsrsi.runtime_stats_interval_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_query_text%20AS%20qsqt%20%0D%0A%20%20%20%20ON%20qsqt.query_text_id%20%3D%20qsq.query_text_id%20%0D%0A%20%20WHERE%20qsrsi.start_time%20%3E%3D%20DATEADD(HOUR%2C%20-2%2C%20GETUTCDATE())%20%0D%0A%20%20GROUP%20BY%20%0D%0A%20%20%20%20qsq.query_id%2C%20%0D%0A%20%20%20%20qsp.query_plan_hash%2C%20%0D%0A%20%20%20%20qsq.query_hash%2C%20%0D%0A%20%20%20%20qsqt.query_sql_text%20%0D%0A)%2C%20%0D%0Amissing_index%20AS%20(%20%0D%0A%20%20SELECT%20DISTINCT%20%0D%0A%20%20%20%20qsq.*%2C%20%0D%0A%20%20%20%20migs.avg_total_user_cost%2C%20%0D%0A%20%20%20%20migs.avg_user_impact%2C%20%0D%0A%20%20%20%20migs.user_seeks%2C%20%0D%0A%20%20%20%20migs.user_scans%2C%20%0D%0A%20%20%20%20mig.index_group_handle%2C%20%0D%0A%20%20%20%20mid.index_handle%2C%20%0D%0A%20%20%20%20mid.statement%2C%20%0D%0A%20%20%20%20mid.equality_columns%2C%20%0D%0A%20%20%20%20mid.inequality_columns%2C%20%0D%0A%20%20%20%20mid.included_columns%2C%20%0D%0A%20%20%20%20mid.object_id%20%0D%0A%20%20FROM%20query_missing_index%20AS%20qsq%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_group_stats_query%20AS%20migsq%20%0D%0A%20%20%20%20ON%20qsq.query_plan_hash%20%3D%20migsq.query_plan_hash%20%0D%0A%20%20%20%20%20%20%20AND%20qsq.query_hash%20%3D%20migsq.query_hash%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_groups%20AS%20mig%20%0D%0A%20%20%20%20ON%20migsq.group_handle%20%3D%20mig.index_group_handle%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_group_stats%20AS%20migs%20%0D%0A%20%20%20%20ON%20migs.group_handle%20%3D%20mig.index_group_handle%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_details%20AS%20mid%20%0D%0A%20%20%20%20ON%20mig.index_handle%20%3D%20mid.index_handle%20%0D%0A)%20%0D%0ASELECT%20%0D%0A%20%20CONVERT%20(VARCHAR(30)%2C%20GETDATE()%2C%20126)%20AS%20runtime%2C%20%0D%0A%20%20avg_user_impact%20AS%20%5BBenefit%20%25%20(Percentage)%5D%2C%20%0D%0A%20%20query_id%2C%20%0D%0A%20%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20query_plan_hash)%2C%202)%20%0D%0A%20%20%20%20AS%20query_plan_hash%2C%20%0D%0A%20%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20query_hash)%2C%202)%20AS%20query_hash%2C%20%0D%0A%20%20query_text%2C%20%0D%0A%20%20'CREATE%20NONCLUSTERED%20INDEX%20%5BNCI_'%20%2B%20OBJECT_NAME(object_id)%20%2B%20'_'%20%0D%0A%20%20%20%20%2B%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20%20%20REPLACE(ISNULL(equality_columns%2C%20'')%2C%20'%2C%20'%2C%20'_')%2C%20%0D%0A%20%20%20%20%20%20%20%20%20%20'%5B'%2C%20'')%2C%20%0D%0A%20%20%20%20%20%20%20%20'%5D'%2C%20'')%20%0D%0A%20%20%20%20%2B%20CASE%20%0D%0A%20%20%20%20%20%20%20%20WHEN%20equality_columns%20IS%20NOT%20NULL%20%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20AND%20inequality_columns%20IS%20NOT%20NULL%20THEN%20'_'%20%0D%0A%20%20%20%20%20%20%20%20ELSE%20''%20%0D%0A%20%20%20%20%20%20END%20%0D%0A%20%20%20%20%2B%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20%20%20REPLACE(ISNULL(inequality_columns%2C%20'')%2C%20'%2C%20'%2C%20'_')%2C%20%0D%0A%20%20%20%20%20%20%20%20%20%20'%5B'%2C%20'')%2C%20%0D%0A%20%20%20%20%20%20%20%20'%5D'%2C%20'')%20%0D%0A%20%20%20%20%2B%20'_'%20%2B%20TRY_CONVERT(varchar%2C%20index_group_handle)%20%2B%20'%5D'%20%0D%0A%20%20%20%20%2B%20'%20ON%20'%20%2B%20statement%20%2B%20'%20('%20%2B%20ISNULL(equality_columns%2C%20'')%20%0D%0A%20%20%20%20%2B%20CASE%20%0D%0A%20%20%20%20%20%20%20%20WHEN%20equality_columns%20IS%20NOT%20NULL%20%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20AND%20inequality_columns%20IS%20NOT%20NULL%20THEN%20'%2C'%20%0D%0A%20%20%20%20%20%20%20%20ELSE%20''%20%0D%0A%20%20%20%20%20%20END%20%0D%0A%20%20%20%20%2B%20ISNULL(inequality_columns%2C%20'')%20%2B%20')'%20%0D%0A%20%20%20%20%2B%20ISNULL('%20INCLUDE%20('%20%2B%20included_columns%20%2B%20')%3B'%2C'')%20%0D%0A%20%20%20%20%2B%20'%20WITH%20(ONLINE%3D%20ON%2C%20RESUMABLE%3DON)%3B'%20AS%20create_index_statement%20%0D%0AFROM%20missing_index%20%0D%0AWHERE%20avg_user_impact%20%3E%2050%20%0D%0A%20%20%20%20%20%20AND%20TRY_CONVERT(%20%0D%0A%20%20%20%20%20%20%20%20decimal%20(28%2C1)%2C%20%0D%0A%20%20%20%20%20%20%20%20avg_total_user_cost%20*%20avg_user_impact%20*%20(user_seeks%20%2B%20user_scans))%20%3E%2010%20%0D%0A%20%20%20%20%20%20AND%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20query_hash)%2C%202)%20%0D%0A%20%20%20%20%20%20%20%20IN%20('0x58DB82ADB688CCB4'%2C'0xD770ACA80BEFB236')%20%0D%0AORDER%20BY%20avg_user_impact%20DESC%3B%0A%0AWITH%20AggregatedCPU%20AS%20(%20%0D%0A%20%20SELECT%20%0D%0A%20%20%20%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20q.query_hash)%2C%202)%20%0D%0A%20%20%20%20%20%20AS%20query_hash%2C%20%0D%0A%20%20%20%20ROUND(SUM(count_executions%20*%20avg_cpu_time%20%2F%201000.0)%2C%203)%20AS%20total_cpu_ms%20%0D%0A%20%20FROM%20sys.query_store_query_text%20AS%20qt%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_query%20AS%20q%20%0D%0A%20%20%20%20ON%20qt.query_text_id%20%3D%20q.query_text_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_plan%20AS%20p%20%0D%0A%20%20%20%20ON%20q.query_id%20%3D%20p.query_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats%20AS%20rs%20%0D%0A%20%20%20%20ON%20rs.plan_id%20%3D%20p.plan_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats_interval%20AS%20rsi%20%0D%0A%20%20%20%20ON%20rsi.runtime_stats_interval_id%20%3D%20rs.runtime_stats_interval_id%20%0D%0A%20%20WHERE%20rs.execution_type_desc%20IN%20('Regular'%2C%20'Aborted'%2C%20'Exception')%20%0D%0A%20%20%20%20%20%20%20%20AND%20rsi.start_time%20%3E%3D%20DATEADD(HOUR%2C%20-2%2C%20GETUTCDATE())%20%0D%0A%20%20GROUP%20BY%20q.query_hash%20%0D%0A)%2C%20%0D%0AOrderedCPU%20AS%20(%20%0D%0A%20%20SELECT%20%0D%0A%20%20%20%20*%2C%20%0D%0A%20%20%20%20ROW_NUMBER()%20OVER%20(ORDER%20BY%20total_cpu_ms%20DESC%2C%20query_hash%20ASC)%20AS%20RN%20%0D%0A%20%20FROM%20AggregatedCPU%20%0D%0A)%20%0D%0ASELECT%20*%20%0D%0AFROM%20OrderedCPU%20AS%20OD%20%0D%0AWHERE%20OD.RN%20%3C%3D%2010%20%0D%0AORDER%20BY%20total_cpu_ms%20DESC%3B\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">here<\/a>\u00a0to view the query or queries we used for your answer in Azure Portal\u2019s SQL editor.\u201d<\/em><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Criei o \u00edndice que ele indicou e fiz a mesma pergunta para ver o que ele me responderia:<\/p>\n<p>Resposta do Copilot:<\/p>\n<p>\u201d<\/p>\n<p><em>Based on the analysis of your query, there are no missing index recommendations or anti-pattern queries detected in your workload. This means that there are no suggestions for creating new indexes to improve the performance of your query, and no anti-patterns were identified in your query that could be causing performance issues.<\/em><\/p>\n<p><em>Anti-patterns are certain query patterns that can lead to suboptimal performance. The types of anti-patterns that Azure SQL\u2019s internal telemetry checks for include type conversion preventing seek, large number of OR in predicate, large IN, and non-optimal OR logic. However, it\u2019s important to note that there may be other types of anti-patterns not detected by the telemetry.<\/em><\/p>\n<p><em>Since no missing index recommendations or anti-pattern queries were found, it suggests that your query is already optimized for the current database schema and workload. However, performance can also be affected by other factors such as recent changes in database workload, so it\u2019s recommended to identify any such changes for further troubleshooting.<\/em><\/p>\n<p><em>For more information on identifying and adding missing indexes, you can refer to this\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/azure-sql\/database\/performance-guidance?view=azuresql#identifying-and-adding-missing-indexes\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">guide<\/a>.<\/em><\/p>\n<p><em>For more information on tuning nonclustered missing index suggestions, you can refer to this\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/indexes\/tune-nonclustered-missing-index-suggestions?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">guide<\/a>.<\/em><\/p>\n<p><em>For more information on performance problems due to antipattern queries, you can refer to this\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/techcommunity.microsoft.com\/t5\/azure-sql-blog\/watch-out-for-performance-problems-due-to-antipattern-queries-in\/ba-p\/3733386\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">blog post<\/a>.<\/em><\/p>\n<p><em>Click\u00a0<a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/sandbox-4.reactblade.portal.azure.net\/React\/Index?reactView=true&amp;retryCount=0&amp;l=en.pt-br&amp;trustedAuthority=https:\/\/portal.azure.com&amp;contentHash=c2Mxl89G2hBx&amp;reactIndex=0&amp;sessionId=f06fad87f3244b18b2a2e9d028834177#view\/SqlAzureExtension\/QueryEditorBlade\/resourceId\/%2Fsubscriptions%2Ff9056425-c4dc-4acd-9a22-3cd547f0e4d3%2FresourceGroups%2FCopilotSQL%2Fproviders%2FMicrosoft.Sql%2Fservers%2Fcopilotsqlbrazil%2Fdatabases%2FCopilotSQL\/queryText\/WITH%20AggregatedCPU%20AS%20(%20%0D%0A%20%20SELECT%20%0D%0A%20%20%20%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20q.query_hash)%2C%202)%20%0D%0A%20%20%20%20%20%20AS%20query_hash%2C%20%0D%0A%20%20%20%20ROUND(SUM(count_executions%20*%20avg_cpu_time%20%2F%201000.0)%2C%203)%20AS%20total_cpu_ms%20%0D%0A%20%20FROM%20sys.query_store_query_text%20AS%20qt%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_query%20AS%20q%20%0D%0A%20%20%20%20ON%20qt.query_text_id%20%3D%20q.query_text_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_plan%20AS%20p%20%0D%0A%20%20%20%20ON%20q.query_id%20%3D%20p.query_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats%20AS%20rs%20%0D%0A%20%20%20%20ON%20rs.plan_id%20%3D%20p.plan_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats_interval%20AS%20rsi%20%0D%0A%20%20%20%20ON%20rsi.runtime_stats_interval_id%20%3D%20rs.runtime_stats_interval_id%20%0D%0A%20%20WHERE%20rs.execution_type_desc%20IN%20('Regular'%2C%20'Aborted'%2C%20'Exception')%20%0D%0A%20%20%20%20%20%20%20%20AND%20rsi.start_time%20%3E%3D%20DATEADD(HOUR%2C%20-2%2C%20GETUTCDATE())%20%0D%0A%20%20GROUP%20BY%20q.query_hash%20%0D%0A)%2C%20%0D%0AOrderedCPU%20AS%20(%20%0D%0A%20%20SELECT%20%0D%0A%20%20%20%20*%2C%20%0D%0A%20%20%20%20ROW_NUMBER()%20OVER%20(ORDER%20BY%20total_cpu_ms%20DESC%2C%20query_hash%20ASC)%20AS%20RN%20%0D%0A%20%20FROM%20AggregatedCPU%20%0D%0A)%20%0D%0ASELECT%20*%20%0D%0AFROM%20OrderedCPU%20AS%20OD%20%0D%0AWHERE%20OD.RN%20%3C%3D%2010%20%0D%0AORDER%20BY%20total_cpu_ms%20DESC%3B%0A%0AWITH%20query_missing_index%20AS%20(%20%0D%0A%20%20SELECT%20%0D%0A%20%20%20%20qsq.query_id%2C%20%0D%0A%20%20%20%20qsp.query_plan_hash%2C%20%0D%0A%20%20%20%20qsq.query_hash%2C%20%0D%0A%20%20%20%20qsqt.query_sql_text%20AS%20query_text%20%0D%0A%20%20FROM%20sys.query_store_query%20AS%20qsq%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_plan%20AS%20qsp%20%0D%0A%20%20%20%20ON%20qsq.query_id%20%3D%20qsp.query_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats%20AS%20qrs%20%0D%0A%20%20%20%20ON%20qsp.plan_id%20%3D%20qrs.plan_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_runtime_stats_interval%20AS%20qsrsi%20%0D%0A%20%20%20%20ON%20qrs.runtime_stats_interval_id%20%3D%20qsrsi.runtime_stats_interval_id%20%0D%0A%20%20INNER%20JOIN%20sys.query_store_query_text%20AS%20qsqt%20%0D%0A%20%20%20%20ON%20qsqt.query_text_id%20%3D%20qsq.query_text_id%20%0D%0A%20%20WHERE%20qsrsi.start_time%20%3E%3D%20DATEADD(HOUR%2C%20-2%2C%20GETUTCDATE())%20%0D%0A%20%20GROUP%20BY%20%0D%0A%20%20%20%20qsq.query_id%2C%20%0D%0A%20%20%20%20qsp.query_plan_hash%2C%20%0D%0A%20%20%20%20qsq.query_hash%2C%20%0D%0A%20%20%20%20qsqt.query_sql_text%20%0D%0A)%2C%20%0D%0Amissing_index%20AS%20(%20%0D%0A%20%20SELECT%20DISTINCT%20%0D%0A%20%20%20%20qsq.*%2C%20%0D%0A%20%20%20%20migs.avg_total_user_cost%2C%20%0D%0A%20%20%20%20migs.avg_user_impact%2C%20%0D%0A%20%20%20%20migs.user_seeks%2C%20%0D%0A%20%20%20%20migs.user_scans%2C%20%0D%0A%20%20%20%20mig.index_group_handle%2C%20%0D%0A%20%20%20%20mid.index_handle%2C%20%0D%0A%20%20%20%20mid.statement%2C%20%0D%0A%20%20%20%20mid.equality_columns%2C%20%0D%0A%20%20%20%20mid.inequality_columns%2C%20%0D%0A%20%20%20%20mid.included_columns%2C%20%0D%0A%20%20%20%20mid.object_id%20%0D%0A%20%20FROM%20query_missing_index%20AS%20qsq%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_group_stats_query%20AS%20migsq%20%0D%0A%20%20%20%20ON%20qsq.query_plan_hash%20%3D%20migsq.query_plan_hash%20%0D%0A%20%20%20%20%20%20%20AND%20qsq.query_hash%20%3D%20migsq.query_hash%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_groups%20AS%20mig%20%0D%0A%20%20%20%20ON%20migsq.group_handle%20%3D%20mig.index_group_handle%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_group_stats%20AS%20migs%20%0D%0A%20%20%20%20ON%20migs.group_handle%20%3D%20mig.index_group_handle%20%0D%0A%20%20INNER%20JOIN%20sys.dm_db_missing_index_details%20AS%20mid%20%0D%0A%20%20%20%20ON%20mig.index_handle%20%3D%20mid.index_handle%20%0D%0A)%20%0D%0ASELECT%20%0D%0A%20%20CONVERT%20(VARCHAR(30)%2C%20GETDATE()%2C%20126)%20AS%20runtime%2C%20%0D%0A%20%20avg_user_impact%20AS%20%5BBenefit%20%25%20(Percentage)%5D%2C%20%0D%0A%20%20query_id%2C%20%0D%0A%20%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20query_plan_hash)%2C%202)%20%0D%0A%20%20%20%20AS%20query_plan_hash%2C%20%0D%0A%20%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20query_hash)%2C%202)%20AS%20query_hash%2C%20%0D%0A%20%20query_text%2C%20%0D%0A%20%20'CREATE%20NONCLUSTERED%20INDEX%20%5BNCI_'%20%2B%20OBJECT_NAME(object_id)%20%2B%20'_'%20%0D%0A%20%20%20%20%2B%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20%20%20REPLACE(ISNULL(equality_columns%2C%20'')%2C%20'%2C%20'%2C%20'_')%2C%20%0D%0A%20%20%20%20%20%20%20%20%20%20'%5B'%2C%20'')%2C%20%0D%0A%20%20%20%20%20%20%20%20'%5D'%2C%20'')%20%0D%0A%20%20%20%20%2B%20CASE%20%0D%0A%20%20%20%20%20%20%20%20WHEN%20equality_columns%20IS%20NOT%20NULL%20%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20AND%20inequality_columns%20IS%20NOT%20NULL%20THEN%20'_'%20%0D%0A%20%20%20%20%20%20%20%20ELSE%20''%20%0D%0A%20%20%20%20%20%20END%20%0D%0A%20%20%20%20%2B%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20REPLACE(%20%0D%0A%20%20%20%20%20%20%20%20%20%20REPLACE(ISNULL(inequality_columns%2C%20'')%2C%20'%2C%20'%2C%20'_')%2C%20%0D%0A%20%20%20%20%20%20%20%20%20%20'%5B'%2C%20'')%2C%20%0D%0A%20%20%20%20%20%20%20%20'%5D'%2C%20'')%20%0D%0A%20%20%20%20%2B%20'_'%20%2B%20TRY_CONVERT(varchar%2C%20index_group_handle)%20%2B%20'%5D'%20%0D%0A%20%20%20%20%2B%20'%20ON%20'%20%2B%20statement%20%2B%20'%20('%20%2B%20ISNULL(equality_columns%2C%20'')%20%0D%0A%20%20%20%20%2B%20CASE%20%0D%0A%20%20%20%20%20%20%20%20WHEN%20equality_columns%20IS%20NOT%20NULL%20%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20AND%20inequality_columns%20IS%20NOT%20NULL%20THEN%20'%2C'%20%0D%0A%20%20%20%20%20%20%20%20ELSE%20''%20%0D%0A%20%20%20%20%20%20END%20%0D%0A%20%20%20%20%2B%20ISNULL(inequality_columns%2C%20'')%20%2B%20')'%20%0D%0A%20%20%20%20%2B%20ISNULL('%20INCLUDE%20('%20%2B%20included_columns%20%2B%20')%3B'%2C'')%20%0D%0A%20%20%20%20%2B%20'%20WITH%20(ONLINE%3D%20ON%2C%20RESUMABLE%3DON)%3B'%20AS%20create_index_statement%20%0D%0AFROM%20missing_index%20%0D%0AWHERE%20avg_user_impact%20%3E%2050%20%0D%0A%20%20%20%20%20%20AND%20TRY_CONVERT(%20%0D%0A%20%20%20%20%20%20%20%20decimal%20(28%2C1)%2C%20%0D%0A%20%20%20%20%20%20%20%20avg_total_user_cost%20*%20avg_user_impact%20*%20(user_seeks%20%2B%20user_scans))%20%3E%2010%20%0D%0A%20%20%20%20%20%20AND%20'0x'%2B%20CONVERT(VARCHAR(16)%2C%20CONVERT(VARBINARY(8)%2C%20query_hash)%2C%202)%20%0D%0A%20%20%20%20%20%20%20%20IN%20('0x58DB82ADB688CCB4'%2C'0xEC3A5BD7A4EC2AAA'%2C'0xD770ACA80BEFB236')%20%0D%0AORDER%20BY%20avg_user_impact%20DESC%3B\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">here<\/a>\u00a0to view the query or queries we used for your answer in Azure Portal\u2019s SQL editor.<\/em><\/p>\n<p>\u201d<\/p>\n<p>Realmente n\u00e3o tem muito o que fazer com essa query ap\u00f3s a cria\u00e7\u00e3o do \u00edndice n\u00e9?<\/p>\n<p>Agora vamos criar um novo problema para essa query para ver se ele consegue analisar.<\/p>\n<p><strong>O famoso e bem comum problema de convers\u00e3o implicita do NVARCHAR x VARCHAR.<\/strong><\/p>\n<p>Problema: Cliente tem uma coluna varchar e faz uma busca passando um parametro nvarchar. O SQL n\u00e3o consegue utilizar o \u00edndice existente na coluna e faz um SCAN.<\/p>\n<p>Simulei esse problema com essa consulta abaixo que por usar o caracter\u00a0<strong>N<\/strong>\u00a0j\u00e1 deixa de fazer um seek no \u00edndice e faz um Scan na tabela:<\/p>\n<div id=\"urvanov-syntax-highlighter-6663267e6148f527675016\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"urvanov-syntax-highlighter-plain-wrap\"><\/div>\n<div class=\"urvanov-syntax-highlighter-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"urvanov-syntax-highlighter-row\">\n<td class=\"crayon-nums\" data-settings=\"show\">\n<div class=\"urvanov-syntax-highlighter-nums-content\">\n<div class=\"crayon-num\" data-line=\"urvanov-syntax-highlighter-6663267e6148f527675016-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"urvanov-syntax-highlighter-6663267e6148f527675016-2\">2<\/div>\n<div class=\"crayon-num crayon-marked-num crayon-top crayon-bottom\" data-line=\"urvanov-syntax-highlighter-6663267e6148f527675016-3\">3<\/div>\n<\/div>\n<\/td>\n<td class=\"urvanov-syntax-highlighter-code\">\n<div class=\"crayon-pre\">\n<div id=\"urvanov-syntax-highlighter-6663267e6148f527675016-1\" class=\"crayon-line\"><span class=\"crayon-e\">SELECT <\/span><span class=\"crayon-e\">DISTINCT <\/span><span class=\"crayon-e\">Name <\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e6148f527675016-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">FROM <\/span><span class=\"crayon-e\">Client <\/span><\/div>\n<div id=\"urvanov-syntax-highlighter-6663267e6148f527675016-3\" class=\"crayon-line crayon-marked-line crayon-top crayon-bottom\"><span class=\"crayon-e\">WHERE <\/span><span class=\"crayon-v\">Name<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-i\">N<\/span><span class=\"crayon-s\">&#8216;Joe Sack good SQL Server player&#8217;<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Fiz a mesma pergunta que antes, mas ele n\u00e3o conseguiu me falar que o\u00a0<strong>N\u00a0<\/strong>me gera um problema de performance e faz minha query fazer um Scan ao inv\u00e9s de um seek.<\/p>\n<p>At\u00e9 tenta me orientar se estou fazendo correto a query, mas a quest\u00e3o da performance n\u00e3o me ajudou:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19593 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303-213x300.jpg\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" srcset=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303-213x300.jpg 213w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303-410x577.jpg 410w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303-100x141.jpg 100w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303-275x387.jpg 275w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303-14x20.jpg 14w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-303.jpg 527w\" alt=\"\" width=\"364\" height=\"512\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19594 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304-226x300.jpg\" sizes=\"auto, (max-width: 356px) 100vw, 356px\" srcset=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304-226x300.jpg 226w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304-410x544.jpg 410w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304-100x133.jpg 100w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304-275x365.jpg 275w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304-15x20.jpg 15w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-304.jpg 491w\" alt=\"\" width=\"356\" height=\"472\" \/><\/p>\n<p>E reparem que ele identificou o N do nvarchar.<\/p>\n<p>Falou que posso omitir, mas n\u00e3o me indicou que isso pode matar a performance do meu ambiente.<\/p>\n<p>Entrei em contato com o time do produto e me falaram para tentar fazer essa pergunta passando o hash da query, que eles ainda est\u00e3o trabalhando nesse tipo de pergunta passando o c\u00f3digo direto no Copilot.<\/p>\n<p>Encontrei o hash da minha query assim:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19596 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-300x114.jpg\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" srcset=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-300x114.jpg 300w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-1024x388.jpg 1024w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-768x291.jpg 768w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-700x266.jpg 700w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-410x156.jpg 410w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-100x38.jpg 100w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-275x104.jpg 275w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306-20x8.jpg 20w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-306.jpg 1339w\" alt=\"\" width=\"739\" height=\"281\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Perguntei ao Copilot e n\u00e3o \u00e9 que ele realmente encontrou que a query cont\u00e9m um\u00a0<strong>anti-pattern:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19599 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern-175x300.jpg\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" srcset=\"https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern-175x300.jpg 175w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern-410x704.jpg 410w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern-100x172.jpg 100w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern-275x472.jpg 275w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern-12x20.jpg 12w, https:\/\/www.fabriciolima.net\/wp-content\/uploads\/2024\/06\/post-307-antipattern.jpg 571w\" alt=\"\" width=\"386\" height=\"662\" \/><\/p>\n<p>Destaque para essa parte:<\/p>\n<p><em>\u201cThe internal SQL telemetry returned a row for the query hash\u00a0<code>0xD770ACA80BEFB236<\/code>, indicating that the query contains an anti-pattern. The anti-pattern type is\u00a0<code>TypeConvertPreventingSeek<\/code>, which means that the query is performing a type conversion that prevents the SQL Server from using an index seek operation, potentially leading to less efficient query execution. The last occurrence of this anti-pattern was on\u00a0<code>2024-06-05 16:10:54<\/code>\u00a0(UTC). You may want to review the query and consider modifying it to avoid this anti-pattern. For more information on anti-pattern queries and how to address them, you can refer to this resource:<\/em><\/p>\n<ul>\n<li>\n<ul>\n<li><em><a class=\"ac-anchor external-link wpel-icon-left\" href=\"https:\/\/techcommunity.microsoft.com\/t5\/azure-sql-blog\/watch-out-for-performance-problems-due-to-antipattern-queries-in\/ba-p\/3733386\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">Watch Out for Performance Problems Due to Antipattern Queries in Azure SQL Database<\/a><\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Nesse link ele mostra os tipos de Anti-Pattern que o Copilot deve pegar (futuros testes que teria que fazer):<\/p>\n<p><em>\u201c<\/em><em>The following are the antipatterns that can be captured during query optimization:<\/em><\/p>\n<ul>\n<li><strong><em>Column data type conversion preventing an index seek (implicit type conversion)* **<\/em><\/strong><\/li>\n<li><em>Non-optimal\/unfriendly OR**<\/em><\/li>\n<li><em>Large IN clause**<\/em><\/li>\n<li><em>Large number of OR predicates**<\/em><\/li>\n<\/ul>\n<p><em>There are other antipattern query scenarios that you should be aware of as you design your application such as:<\/em><\/p>\n<ul>\n<li><em>Non-parameterized\/ad-hoc workloads<\/em><\/li>\n<li><em>Improper transaction management<\/em><\/li>\n<li><em>Non-SARGable predicates<\/em><\/li>\n<\/ul>\n<p>Agora sim o Copilot deu a resposta que eu queria e mostrando de forma bem clara que a convers\u00e3o piora a performance da query:<\/p>\n<p><strong><em>\u201cThe anti-pattern type is\u00a0<code>TypeConvertPreventingSeek<\/code>, which means that the query is performing a type conversion that prevents the SQL Server from using an index seek operation, potentially leading to less efficient query execution.\u201d<\/em><\/strong><\/p>\n<p>J\u00e1 perdi as contas de quantas queries j\u00e1 melhoramos s\u00f3 de acertar essa convers\u00e3o implicita do nvarchar para o varchar.<\/p>\n<p>Ainda precisou de eu passar o hash da query, mas em breve n\u00e3o deve precisar e mesmo quem n\u00e3o \u00e9 DBA, que consegue ver o problema s\u00f3 de olhar a query, vai ter essa indica\u00e7\u00e3o de problema pelo Copilot.<\/p>\n<p>Sensacional n\u00e9!?<\/p>\n<p>E \u00e9 s\u00f3 o come\u00e7o. Isso ainda deve evoluir demais e ficar cada vez mais r\u00e1pido as respostas.<\/p>\n<p>Quer ficar por dentro das novidades do mundo da IA e aprender junto com nosso Head de IA Rodrigo Ribeiro?<\/p>\n<ul>\n<li><a class=\"external-link wpel-icon-left\" href=\"https:\/\/www.linkedin.com\/in\/rodrigoribeirogomes\/\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">Siga o Rodrigo no Linkedin<\/a><\/li>\n<\/ul>\n<p>O Rodrigo criou um instagram, blog e canal no youtube s\u00f3 para falar der IA, o IA Talking. N\u00e3o deixem de acompanhar:<\/p>\n<ul>\n<li><a class=\"external-link wpel-icon-left\" href=\"https:\/\/www.youtube.com\/@IATalking\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">Canal IA Talking Youtube<\/a><\/li>\n<li><a class=\"external-link wpel-icon-left\" href=\"https:\/\/iatalk.ing\/\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">Blog IA Talking<\/a><\/li>\n<li><a class=\"external-link wpel-icon-left\" href=\"https:\/\/www.tiktok.com\/@iatalking\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">Tiktok @iatalking<\/a><\/li>\n<li><a class=\"external-link wpel-icon-left\" href=\"https:\/\/www.instagram.com\/iatalking\/\" target=\"_blank\" rel=\"noopener nofollow external noreferrer\" data-wpel-link=\"external\">Instagram @iatalking<\/a><\/li>\n<\/ul>\n<p>Veja outros posts sobre o assunto:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.fabriciolima.net\/blog\/2024\/05\/22\/azure-sql-copilot-01-identificando-locks-no-bd-perguntando-ao-copilot\/\" target=\"_blank\" rel=\"noopener\" data-wpel-link=\"internal\">Azure SQL Copilot (#01) \u2013 Identificando Locks no BD apenas perguntando ao Copilot<\/a><\/li>\n<li><a href=\"https:\/\/www.fabriciolima.net\/blog\/2024\/05\/31\/azure-sql-copilot-02-qual-query-o-copilot-usa-para-validar-a-performance-do-bd\/\" target=\"_blank\" rel=\"noopener\" data-wpel-link=\"internal\">Azure SQL Copilot (#02) \u2013 Qual query o Copilot usa para validar a performance do BD?<\/a><\/li>\n<\/ul>\n<p>At\u00e9 o pr\u00f3ximo artigo.<\/p>\n<p>Abra\u00e7os,<br \/>\nFabr\u00edcio Lima<br \/>\nCEO na Fabr\u00edcio Lima Solu\u00e7\u00f5es em BD<br \/>\nMicrosoft Data Platform MVP<br \/>\nInstagram:<a class=\"external-link wpel-icon-left\" href=\"https:\/\/www.instagram.com\/fabriciofrancalima\/\" target=\"_blank\" rel=\"noopener external noreferrer nofollow\" data-wpel-link=\"external\">@fabriciofrancalima<\/a><br \/>\nLinkedin:\u00a0<a class=\"external-link wpel-icon-left\" href=\"https:\/\/www.linkedin.com\/in\/fabriciofrancalima\/\" target=\"_blank\" rel=\"noopener noreferrer external nofollow\" data-wpel-link=\"external\">https:\/\/www.linkedin.com\/in\/fabriciofrancalima\/<\/a><br \/>\nConsultoria:\u00a0comercial@powertuning.com.br<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fala Pessoal, Seguimos aqui nos testes e feedbacks do SQL Copilot para o time de produto. Dessa vez vou mostrar se ele consegue analisar uma query, que provavelmente ser\u00e1 uma das coisas que os clientes mais devem usar nele, principalmente quem n\u00e3o tem um DBA interno. Criei uma tabela de teste e inseri alguns registros:&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/powertuning.com.br\/blog\/azure-sql-copilot-sera-que-ele-consegue-analisar-uma-query-e-sugerir-melhorias\/\">Leia mais<\/a><\/p>\n","protected":false},"author":6,"featured_media":3135,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[101,160,63],"tags":[104,13,27,35],"class_list":["post-3134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-inteligencia-artificial","category-sql-server","tag-azure","tag-banco-de-dados","tag-power-bi","tag-sql-server"],"jetpack_featured_media_url":"https:\/\/powertuning.com.br\/blog\/wp-content\/uploads\/2024\/06\/Novidade-no-blog54.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/posts\/3134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/comments?post=3134"}],"version-history":[{"count":2,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/posts\/3134\/revisions"}],"predecessor-version":[{"id":3138,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/posts\/3134\/revisions\/3138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/media\/3135"}],"wp:attachment":[{"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/media?parent=3134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/categories?post=3134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/powertuning.com.br\/blog\/wp-json\/wp\/v2\/tags?post=3134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}