Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42271

Save ANALYZE FORMAT=JSON output in the slow query log

    XMLWordPrintable

Details

    Description

      Many performance analysis tasks require capturing of ANALYZE FORMAT=JSON output of many queries.

      Use cases

      Major:

      Recent use cases:
      Run a workload. Which queries used parallel query?
      Run a benchmark. Did any queries use PTRC optimization? What was the cache hit ratio?

      Run workload with different settings. Did query plans change?

      Minor:
      In mtr testcase, we only need to examine a part of ANALYZE FORMAT=JSON. One can try achieving it like this:

      let $json=`ANALYZE FORMAT=JSON SELECT ...` ;
      evalp set @var='$json' ;
      select JSON_PRETTY(JSON_EXTRACT(@var, '$.path.to.something'));
      

      But the SET will fail if $json has quotes.

      MySQL 9.0+ has a more straightforward syntax:

      EXPLAIN FORMAT=JSON INTO @var SELECT ... ;
      

      The query produces nothing and the EXPLAIN output goes into @var

      Where to save it

      For the major use case of storing all ANALYZE outputs:
      Q: do we need to enable access timings? How much impact that will have?

      Table-based slow query log

      This looks the most natural, but it does not have space for most of log-slow-verbosity extensions?
      Does this mean that most users do not use this?

      We could add two JSON fields:

      • One for ANALYZE FORMAT=JSON
      • One for all other members that file-based slow query log has.

      File-based slow query log

      It follows the log-slow-verbosity= ... settings.
      Extra data is printed as # comments, followed by the query which is not commented-out.
      We can't have

      SET @analyze_json='(the text)' ;
      SELECT ... (the query) 
      

      as that will break slow query log analysis.

      Tabular EXPLAIN is prefixed # explain:.
      We could also print the JSON output as one line:

      # analyze_json = '(analyze format=json output with any formatting removed)'
      

      The problem here is how to do the processing. You can't read this back into SQL, you'll need perl to parse it.

      Put JSONs into an extra file?

      We could also write ANALYZE FORMAT=JSON outputs into separate file. This seems like over-engineering.
      Q: When audit log is written in JSON format, is it a single huge JSON document? Or a file having many JSON docs?
      A: many.

      Attachments

        Activity

          People

            bsrikanth Srikanth Bondalapati
            psergei Sergei Petrunia
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 15d
                15d
                Remaining:
                Remaining Estimate - 15d
                15d
                Logged:
                Time Spent - Not Specified
                Not Specified

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.