MySQL 8.1.0
Source Code Documentation
column_statistics_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD__COLUMN_STATISTIC_IMPL_INCLUDED
24#define DD__COLUMN_STATISTIC_IMPL_INCLUDED
25
26#include <stdio.h>
27#include <algorithm>
28#include <new>
29
30#include "my_alloc.h"
31#include "my_inttypes.h"
32#include "my_sys.h"
33#include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
34#include "sql/dd/object_id.h" // dd::Object_id
35#include "sql/dd/sdi_fwd.h"
36#include "sql/dd/string_type.h"
37#include "sql/dd/types/column_statistics.h" // dd::Column_statistics
39#include "sql/psi_memory_key.h" // key_memory_DD_column_statistics
40
41class THD;
42
43namespace dd {
44
45///////////////////////////////////////////////////////////////////////////
46
47class Open_dictionary_tables_ctx;
48class Raw_record;
49class Sdi_rcontext;
50class Sdi_wcontext;
51class Weak_object;
52class Object_table;
53
54///////////////////////////////////////////////////////////////////////////
55
57 public Column_statistics {
58 public:
62 }
63
64 private:
73
74 if (column_statistics.m_histogram != nullptr)
75 m_histogram = column_statistics.m_histogram->clone(&m_mem_root);
76 }
77
78 public:
79 const Object_table &object_table() const override;
80
82
83 bool validate() const override { return m_histogram == nullptr; }
84
85 bool store_attributes(Raw_record *r) override;
86
87 bool restore_attributes(const Raw_record &r) override;
88
89 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
90
91 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
92
93 const String_type &schema_name() const override { return m_schema_name; }
94
95 void set_schema_name(const String_type &schema_name) override {
97 }
98
99 const String_type &table_name() const override { return m_table_name; }
100
101 void set_table_name(const String_type &table_name) override {
103 }
104
105 const String_type &column_name() const override { return m_column_name; }
106
109 }
110
111 const histograms::Histogram *histogram() const override {
112 return m_histogram;
113 }
114
116 // Free any existing histogram data
118
119 // Take responsibility for the MEM_ROOT of the histogram provided
120 m_mem_root = std::move(*histogram->get_mem_root());
121 m_histogram = std::move(histogram);
122 }
123
125
126 const Entity_object_impl *impl() const override {
128 }
129
130 Object_id id() const override { return Entity_object_impl::id(); }
131
132 bool is_persistent() const override {
134 }
135
136 const String_type &name() const override {
138 }
139
140 void set_name(const String_type &name) override {
142 }
143
144 void debug_print(String_type &outb) const override {
145 char outbuf[1024];
146 sprintf(outbuf,
147 "COLUMN STATISTIC OBJECT: id= {OID: %lld}, name= %s, "
148 "schema_name= %s, table_name= %s, column_name= %s",
149 id(), name().c_str(), schema_name().c_str(), table_name().c_str(),
150 column_name().c_str());
151 outb = String_type(outbuf);
152 }
153
154 private:
159
160 Column_statistics *clone() const override {
161 return new Column_statistics_impl(*this);
162 }
163
166 placeholder->set_id(id());
167 placeholder->set_name(name());
168 /*
169 Even though schema, table and column name members are not used in keys
170 directly, they are still used to check that correct metadata locks are
171 held, so for safety we copy them as well.
172 */
173 placeholder->set_schema_name(schema_name());
174 placeholder->set_table_name(table_name());
175 placeholder->set_column_name(column_name());
176 return placeholder;
177 }
178};
179
180///////////////////////////////////////////////////////////////////////////
181
182} // namespace dd
183
184#endif // DD__COLUMN_STATISTIC_IMPL_INCLUDED
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: column_statistics_impl.h:57
const String_type & table_name() const override
Definition: column_statistics_impl.h:99
void set_schema_name(const String_type &schema_name) override
Definition: column_statistics_impl.h:95
const Entity_object_impl * impl() const override
Definition: column_statistics_impl.h:126
Object_id id() const override
The unique dictionary object id.
Definition: column_statistics_impl.h:130
Column_statistics_impl(const Column_statistics_impl &column_statistics)
Definition: column_statistics_impl.h:65
void set_histogram(const histograms::Histogram *histogram) override
Definition: column_statistics_impl.h:115
const String_type & name() const override
Definition: column_statistics_impl.h:136
const String_type & schema_name() const override
Definition: column_statistics_impl.h:93
Entity_object_impl * impl() override
Definition: column_statistics_impl.h:124
const histograms::Histogram * histogram() const override
Definition: column_statistics_impl.h:111
bool store_attributes(Raw_record *r) override
Definition: column_statistics_impl.cc:130
bool validate() const override
Definition: column_statistics_impl.h:83
String_type m_table_name
Definition: column_statistics_impl.h:156
const String_type & column_name() const override
Definition: column_statistics_impl.h:105
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
Definition: column_statistics_impl.cc:173
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override
Converts *this into json.
Definition: column_statistics_impl.cc:152
Column_statistics_impl()
Definition: column_statistics_impl.h:59
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: column_statistics_impl.cc:209
bool restore_attributes(const Raw_record &r) override
Definition: column_statistics_impl.cc:102
const histograms::Histogram * m_histogram
Definition: column_statistics_impl.h:158
void set_column_name(const String_type &column_name) override
Definition: column_statistics_impl.h:107
Column_statistics * clone() const override
Definition: column_statistics_impl.h:160
void set_table_name(const String_type &table_name) override
Definition: column_statistics_impl.h:101
String_type m_schema_name
Definition: column_statistics_impl.h:155
void set_name(const String_type &name) override
Definition: column_statistics_impl.h:140
Column_statistics * clone_dropped_object_placeholder() const override
Allocate a new object which can serve as a placeholder for the original object in the Dictionary_clie...
Definition: column_statistics_impl.h:164
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: column_statistics_impl.h:132
void debug_print(String_type &outb) const override
Definition: column_statistics_impl.h:144
String_type m_column_name
Definition: column_statistics_impl.h:157
const Object_table & object_table() const override
Definition: column_statistics_impl.cc:203
Definition: column_statistics.h:52
MEM_ROOT m_mem_root
MEM_ROOT on which the histogram data is allocated.
Definition: column_statistics.h:55
Definition: entity_object_impl.h:43
void set_name(const String_type &name) override
Definition: entity_object_impl.h:61
void set_id(Object_id id)
Definition: entity_object_impl.h:50
Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:48
const String_type & name() const override
Definition: entity_object_impl.h:59
Entity_object_impl * impl() override
Definition: entity_object_impl.h:67
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:56
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:71
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:75
Definition: raw_record.h:45
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:230
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:128
Base class for all data dictionary objects.
Definition: weak_object.h:41
Histogram base class.
Definition: histogram.h:291
MEM_ROOT * get_mem_root() const
Definition: histogram.h:500
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
Histogram base class.
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
Some integer typedefs for easier portability.
Common header for many mysys elements.
static bool column_statistics
Definition: mysqldump.cc:133
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:63
unsigned long long Object_id
Definition: object_id.h:30
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:48
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
PSI_memory_key key_memory_DD_column_statistics
Definition: psi_memory_key.cc:37
This header provides Rapidjson Type Aliases.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
void Clear()
Deallocate all the RAM used.
Definition: my_alloc.cc:170