2 Replies Latest reply on Jun 3, 2016 10:54 AM by xtraspecialj

    How to use the "QUERYPLAN" Function in SWQL Studio?

    xtraspecialj

      Now that SWQL Studio has functions auto-complete for us, I notice some functions pop up that I've not seen before.  One of those is QueryPlan.  Looking in the SWQL documentation I don't see anything about it.  I happen to need it though since I'm trying to figure out why a query I just wrote is running rather slowly and would like to see if this function can show me what the query plan is and help me track down where the slowness may be coming from.

       

      So, like the title says, how to use it?

        • Re: How to use the "QUERYPLAN" Function in SWQL Studio?
          Jan Pelousek

          Hello, this function is more for internal diagnostics while development, so that's why it's not public documented/officialy supported. However when you already discovered this, you'll just append WITH QUERYPLAN statement after your query. However I'd say the only thing usable for you in this case will be the output query to the SQL. Example: Select xxx from Orion.Yyy WITH QUERYPLAN

            • Re: How to use the "QUERYPLAN" Function in SWQL Studio?
              xtraspecialj

              Great, thanks for the info.  I did get it to work and yeah, the QUERYPLAN function doesn't produce a helpful diagram like viewing the Query Plan in SQL Server Management Studio.  You mention that the only thing usable for me in this case will be the output query to SQL.  What do you mean by that?  Do you mean I should manually convert the query to SQL and use the Query Plan feature there to pinpoint slow areas of the query (if so, that is what I did and found that I should have been using a "SELECT DISTINCT" for some of my subqueries)?  Or do you mean there is a way for SWQL Studio to show me the actual SQL Query it runs when I run the SWQL query?  The QueryPlan does show the query in the PassThrough section of the XML code it produces, but that looks like a SWQL query since it has functions like "TOSTRING" and table names like "Orion.APM.Component", which are SWQL only items.