summaryrefslogtreecommitdiff
path: root/sql/sql_analyze_stmt.cc
blob: d2eb46298f170b7262e232a65bfa423ce12cd3ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
   Copyright (c) 2015 MariaDB Corporation Ab

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation				// gcc: Class implementation
#endif

#include <my_global.h>
#include "sql_priv.h"
#include "sql_select.h"
#include "my_json_writer.h"

void Filesort_tracker::print_json_members(Json_writer *writer)
{
  const char *varied_str= "(varied across executions)";
  writer->add_member("r_loops").add_ll(r_loops);
  
  if (r_limit != HA_POS_ERROR)
  {
    writer->add_member("r_limit");
    if (r_limit == 0)
      writer->add_str(varied_str);
    else
      writer->add_ll(rint(r_limit/r_loops));
  }

  writer->add_member("r_used_priority_queue"); 
  if (r_used_pq == r_loops)
    writer->add_bool(true);
  else if (r_used_pq == 0)
    writer->add_bool(false);
  else
    writer->add_str(varied_str);

  writer->add_member("r_output_rows").add_ll(rint(r_output_rows / r_loops));

  if (sort_passes)
    writer->add_member("r_sort_passes").add_ll(rint(sort_passes / r_loops));

  if (sort_buffer_size != 0)
  {
    writer->add_member("r_buffer_size");
    if (sort_buffer_size == ulonglong(-1))
      writer->add_str(varied_str);
    else
      writer->add_size(sort_buffer_size);
  }
}


/* 
  Report that we are doing a filesort. 
    @return 
      Tracker object to be used with filesort
*/

Filesort_tracker *Sort_and_group_tracker::report_sorting()
{
  DBUG_ASSERT(cur_action < MAX_QEP_ACTIONS);

  if (total_actions)
  {
    /* This is not the first execution. Check */
    if (qep_actions[cur_action] != EXPL_ACTION_FILESORT)
    {
      varied_executions= true;
      cur_action++;
      if (!dummy_fsort_tracker)
        dummy_fsort_tracker= new (current_thd->mem_root) Filesort_tracker();
      return dummy_fsort_tracker;
    }
    return qep_actions_data[cur_action++].filesort_tracker;
  }

  Filesort_tracker *fs_tracker= new(current_thd->mem_root)Filesort_tracker();
  qep_actions_data[cur_action].filesort_tracker= fs_tracker;
  qep_actions[cur_action++]= EXPL_ACTION_FILESORT;

  return fs_tracker;
}


void Sort_and_group_tracker::report_tmp_table(TABLE *tbl)
{
  DBUG_ASSERT(cur_action < MAX_QEP_ACTIONS);
  if (total_actions)
  {
    /* This is not the first execution. Check if the steps match.  */
    // todo: should also check that tmp.table kinds are the same.
    if (qep_actions[cur_action] != EXPL_ACTION_TEMPTABLE)
      varied_executions= true;
  }

  if (!varied_executions)
  {
    qep_actions[cur_action]= EXPL_ACTION_TEMPTABLE;
    // qep_actions_data[cur_action]= ....
  }
  
  cur_action++;
}