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

Optimizer trace: what's on the execution path when trace=off?

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Done
    • N/A
    • Optimizer
    • None

    Description

      Need to check again what is on the execution path (and so adds CPU overhead), when the tracing is not enabled.

      The original tracing proposal had everything wrapped inside if-statements, something like

      #define OPT_TRACE(thd_arg, X)  if (unlikely(thd_arg->trace_enabled))  { X; }
      

      With tracing code using RAII objects, we can't have everything inside if-s.
      MySQL doesn't have everything inside if-statements either.
      What is the added overhead?

      Attachments

        Issue Links

          Activity

            Examples from MySQL 8.0 codebase:

            static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
            ...
            {
              ...
              Opt_trace_array ota(trace, "range_scan_alternatives");
            

            Opt_trace_array ctor:

              Opt_trace_array(..):
                  : Opt_trace_struct(ctx, false, key, feature) {}
            

            Opt_trace struct constructor:

              Opt_trace_struct(Opt_trace_context *ctx_arg, ...
              {
                // A first inlined test
                if (unlikely(ctx_arg->is_started())) {
                   ...
            

            The destructor is also on the execution path

              ~Opt_trace_struct() {
                if (unlikely(started)) do_destruct();
              }
            

            psergei Sergei Petrunia added a comment - Examples from MySQL 8.0 codebase: static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree, ... { ... Opt_trace_array ota(trace, "range_scan_alternatives" ); Opt_trace_array ctor: Opt_trace_array(..): : Opt_trace_struct(ctx, false , key, feature) {} Opt_trace struct constructor: Opt_trace_struct(Opt_trace_context *ctx_arg, ... { // A first inlined test if (unlikely(ctx_arg->is_started())) { ... The destructor is also on the execution path ~Opt_trace_struct() { if (unlikely(started)) do_destruct(); }

            Besides creating/deleting the RAII tracing objects, the code also has calls to print things into trace:

                  Opt_trace_object trace_idx(trace);
            ...
                  trace_idx.add_utf8("index", param->table->key_info[keynr].name);
            ...
                  trace_idx.add("chosen", true);
            

            The printing methods start with a check of whether the trace is enabled:

              Opt_trace_struct &add(const char *key, bool value) {
                if (likely(!started)) return *this;
                return do_add(key, value);
              }
            

            psergei Sergei Petrunia added a comment - Besides creating/deleting the RAII tracing objects, the code also has calls to print things into trace: Opt_trace_object trace_idx(trace); ... trace_idx.add_utf8( "index" , param->table->key_info[keynr].name); ... trace_idx.add( "chosen" , true ); The printing methods start with a check of whether the trace is enabled: Opt_trace_struct &add( const char *key, bool value) { if (likely(!started)) return * this ; return do_add(key, value); }

            Summary

            When the optimizer trace is off, the following things are on the execution path:

            • Construction/destruction of RAII tracing objects. Both constructor and destructor start with if (tracing_enabled), so no actions are performed if the trace is disabled.
            • Calls to print named values. The printing functions start with if (tracing_enabled).
            • Checks if tracing is enabled if (thd->opt_trace.is_started()) which wrap printing of complex structures.

            I think this is as good as one can reasonably get.

            psergei Sergei Petrunia added a comment - Summary When the optimizer trace is off, the following things are on the execution path: Construction/destruction of RAII tracing objects. Both constructor and destructor start with if (tracing_enabled) , so no actions are performed if the trace is disabled. Calls to print named values. The printing functions start with if (tracing_enabled) . Checks if tracing is enabled if (thd->opt_trace.is_started()) which wrap printing of complex structures. I think this is as good as one can reasonably get.

            Closing as "Done"

            psergei Sergei Petrunia added a comment - Closing as "Done"

            People

              psergei Sergei Petrunia
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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