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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
|
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
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, version 2.0, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef DD__OBJECT_KEYS_INCLUDED
#define DD__OBJECT_KEYS_INCLUDED
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include "m_ctype.h"
#include "my_inttypes.h"
#include "sql/dd/impl/object_key.h" // dd::Object_key
#include "sql/dd/object_id.h" // dd::Object_id
#include "sql/dd/string_type.h"
#include "template_utils.h"
namespace dd {
///////////////////////////////////////////////////////////////////////////
class Raw_table;
struct Raw_key;
///////////////////////////////////////////////////////////////////////////
// NOTE: the current naming convention is as follows:
// - use '_key' suffix to name keys identifying 0 or 1 row;
// - use '_range_key' suffix to name keys identifying 0 or N rows.
///////////////////////////////////////////////////////////////////////////
// Key type to be used for keys that are not supported by an object type.
class Void_key : public Object_key {
public:
Void_key() = default;
public:
/* purecov: begin inspected */
Raw_key *create_access_key(Raw_table *) const override { return nullptr; }
/* purecov: end */
/* purecov: begin inspected */
String_type str() const override { return ""; }
/* purecov: end */
// We need a comparison operator since the type will be used
// as a template type argument.
/* purecov: begin inspected */
bool operator<(const Void_key &rhs) const { return this < &rhs; }
/* purecov: end */
};
///////////////////////////////////////////////////////////////////////////
// Entity_object-id primary key for global objects.
class Primary_id_key : public Object_key {
public:
Primary_id_key() = default;
Primary_id_key(Object_id object_id) : m_object_id(object_id) {}
// Update a preallocated instance.
void update(Object_id object_id) { m_object_id = object_id; }
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
bool operator<(const Primary_id_key &rhs) const {
return m_object_id < rhs.m_object_id;
}
private:
Object_id m_object_id;
};
///////////////////////////////////////////////////////////////////////////
// Entity_object-id partial key for looking for containing objects.
class Parent_id_range_key : public Object_key {
public:
Parent_id_range_key(int id_index_no, int id_column_no, Object_id object_id)
: m_id_index_no(id_index_no),
m_id_column_no(id_column_no),
m_object_id(object_id) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_id_index_no;
int m_id_column_no;
Object_id m_object_id;
};
///////////////////////////////////////////////////////////////////////////
// Entity_object-name key for global objects.
class Global_name_key : public Object_key {
public:
Global_name_key() = default;
Global_name_key(int name_column_no, const String_type &object_name,
const CHARSET_INFO *cs)
: m_name_column_no(name_column_no),
m_object_name(object_name),
m_cs(cs) {}
// Update a preallocated instance.
void update(int name_column_no, const String_type &object_name,
const CHARSET_INFO *cs) {
m_name_column_no = name_column_no;
m_object_name = object_name;
m_cs = cs;
}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
/* purecov: begin inspected */
String_type str() const override { return m_object_name; }
/* purecov: end */
bool operator<(const Global_name_key &rhs) const {
return (my_strnncoll(m_cs,
pointer_cast<const uchar *>(m_object_name.c_str()),
m_object_name.length(),
pointer_cast<const uchar *>(rhs.m_object_name.c_str()),
rhs.m_object_name.length()) < 0);
}
private:
int m_name_column_no;
String_type m_object_name;
// Collation used for the name in the table.
const CHARSET_INFO *m_cs;
};
///////////////////////////////////////////////////////////////////////////
// Entity_object-name key for objects which are identified within a container.
class Item_name_key : public Object_key {
public:
Item_name_key() = default;
Item_name_key(int container_id_column_no, Object_id container_id,
int name_column_no, const String_type &object_name,
const CHARSET_INFO *cs)
: m_container_id_column_no(container_id_column_no),
m_name_column_no(name_column_no),
m_container_id(container_id),
m_object_name(object_name),
m_cs(cs) {}
// Update a preallocated instance.
void update(int container_id_column_no, Object_id container_id,
int name_column_no, const String_type &object_name,
const CHARSET_INFO *cs) {
m_container_id_column_no = container_id_column_no;
m_name_column_no = name_column_no;
m_container_id = container_id;
m_object_name = object_name;
m_cs = cs;
}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
bool operator<(const Item_name_key &rhs) const {
if (m_container_id != rhs.m_container_id)
return (m_container_id < rhs.m_container_id);
return (my_strnncoll(m_cs,
pointer_cast<const uchar *>(m_object_name.c_str()),
m_object_name.length(),
pointer_cast<const uchar *>(rhs.m_object_name.c_str()),
rhs.m_object_name.length()) < 0);
}
private:
int m_container_id_column_no;
int m_name_column_no;
Object_id m_container_id;
String_type m_object_name;
// Collation used for the name in the table.
const CHARSET_INFO *m_cs;
};
///////////////////////////////////////////////////////////////////////////
// TODO: find a better name.
class Se_private_id_key : public Object_key {
public:
Se_private_id_key() = default;
/* purecov: begin deadcode */
Se_private_id_key(int index_no, int engine_column_no,
const String_type &engine, int private_id_column_no,
Object_id private_id)
: m_index_no(index_no),
m_engine_column_no(engine_column_no),
m_engine(engine),
m_private_id_column_no(private_id_column_no),
m_private_id(private_id) {}
/* purecov: end */
// Update a preallocated instance.
void update(int index_no, int engine_column_no, const String_type &engine,
int private_id_column_no, Object_id private_id) {
m_index_no = index_no;
m_engine_column_no = engine_column_no;
m_engine = engine;
m_private_id_column_no = private_id_column_no;
m_private_id = private_id;
}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
bool operator<(const Se_private_id_key &rhs) const {
return m_private_id < rhs.m_private_id ? true
: rhs.m_private_id < m_private_id ? false
: m_engine < rhs.m_engine;
}
private:
int m_index_no;
int m_engine_column_no;
String_type m_engine;
int m_private_id_column_no;
Object_id m_private_id;
};
///////////////////////////////////////////////////////////////////////////
class Composite_pk : public Object_key {
public:
Composite_pk(int index_no, uint first_column_no, Object_id first_id,
uint second_column_no, Object_id second_id)
: m_index_no(index_no),
m_first_column_no(first_column_no),
m_first_id(first_id),
m_second_column_no(second_column_no),
m_second_id(second_id) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_first_column_no;
Object_id m_first_id;
int m_second_column_no;
Object_id m_second_id;
};
///////////////////////////////////////////////////////////////////////////
class Composite_char_key : public Object_key {
public:
Composite_char_key(int index_no, uint first_column_no,
const String_type &first_name, uint second_column_no,
const String_type &second_name)
: m_index_no(index_no),
m_first_column_no(first_column_no),
m_first_name(first_name),
m_second_column_no(second_column_no),
m_second_name(second_name) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_first_column_no;
String_type m_first_name;
int m_second_column_no;
String_type m_second_name;
};
///////////////////////////////////////////////////////////////////////////
class Composite_4char_key : public Object_key {
public:
Composite_4char_key(int index_no, uint first_column_no,
const String_type &first_name, uint second_column_no,
const String_type &second_name, uint third_column_no,
const String_type &third_name, uint fourth_column_no,
const String_type &fourth_name)
: m_index_no(index_no),
m_first_column_no(first_column_no),
m_first_name(first_name),
m_second_column_no(second_column_no),
m_second_name(second_name),
m_third_column_no(third_column_no),
m_third_name(third_name),
m_fourth_column_no(fourth_column_no),
m_fourth_name(fourth_name) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_first_column_no;
String_type m_first_name;
int m_second_column_no;
String_type m_second_name;
int m_third_column_no;
String_type m_third_name;
int m_fourth_column_no;
String_type m_fourth_name;
};
///////////////////////////////////////////////////////////////////////////
class Composite_obj_id_3char_key : public Object_key {
public:
Composite_obj_id_3char_key(int index_no, uint id_column_no, Object_id id,
uint first_column_no,
const String_type &first_name,
uint second_column_no,
const String_type &second_name,
uint third_column_no,
const String_type &third_name)
: m_index_no(index_no),
m_id_column_no(id_column_no),
m_id(id),
m_first_column_no(first_column_no),
m_first_name(first_name),
m_second_column_no(second_column_no),
m_second_name(second_name),
m_third_column_no(third_column_no),
m_third_name(third_name) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_id_column_no;
Object_id m_id;
int m_first_column_no;
String_type m_first_name;
int m_second_column_no;
String_type m_second_name;
int m_third_column_no;
String_type m_third_name;
};
///////////////////////////////////////////////////////////////////////////
// Range key to find index statistics entries by table name.
// in mysql.index_stats.
class Index_stat_range_key : public Object_key {
public:
Index_stat_range_key(int index_no, int schema_name_column_no,
const String_type &schema_name, int table_name_column_no,
const String_type &table_name)
: m_index_no(index_no),
m_schema_name_column_no(schema_name_column_no),
m_schema_name(schema_name),
m_table_name_column_no(table_name_column_no),
m_table_name(table_name) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_schema_name_column_no;
String_type m_schema_name;
int m_table_name_column_no;
String_type m_table_name;
};
///////////////////////////////////////////////////////////////////////////
class Routine_name_key : public Object_key {
public:
Routine_name_key() = default;
Routine_name_key(int index_no, int container_id_column_no,
Object_id container_id, int type_column_no, uint type,
int name_column_no, const String_type &object_name,
const CHARSET_INFO *cs)
: m_index_no(index_no),
m_container_id_column_no(container_id_column_no),
m_type_column_no(type_column_no),
m_name_column_no(name_column_no),
m_container_id(container_id),
m_type(type),
m_object_name(object_name),
m_cs(cs) {}
// Update a preallocated instance.
void update(int index_no, int container_id_column_no, Object_id container_id,
int type_column_no, uint type, int name_column_no,
const String_type &object_name, const CHARSET_INFO *cs) {
m_index_no = index_no;
m_container_id_column_no = container_id_column_no;
m_type_column_no = type_column_no;
m_name_column_no = name_column_no;
m_container_id = container_id;
m_type = type;
m_object_name = object_name;
m_cs = cs;
}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
bool operator<(const Routine_name_key &rhs) const;
private:
int m_index_no;
int m_container_id_column_no;
int m_type_column_no;
int m_name_column_no;
Object_id m_container_id;
uint m_type;
String_type m_object_name;
// Collation used for the routine name in the table.
const CHARSET_INFO *m_cs;
};
///////////////////////////////////////////////////////////////////////////
// Range key to find rows using catalog/schema/table name.
class Table_reference_range_key : public Object_key {
public:
Table_reference_range_key(int index_no, int catalog_name_column_no,
const String_type &catalog_name,
int schema_name_column_no,
const String_type &schema_name,
int table_name_column_no,
const String_type &table_name)
: m_index_no(index_no),
m_catalog_name_column_no(catalog_name_column_no),
m_catalog_name(catalog_name),
m_schema_name_column_no(schema_name_column_no),
m_schema_name(schema_name),
m_table_name_column_no(table_name_column_no),
m_table_name(table_name) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_catalog_name_column_no;
String_type m_catalog_name;
int m_schema_name_column_no;
String_type m_schema_name;
int m_table_name_column_no;
String_type m_table_name;
};
///////////////////////////////////////////////////////////////////////////
// Range key to find sub partition entries by table id and parent partition
// id in mysql.partitions.
class Sub_partition_range_key : public Object_key {
public:
Sub_partition_range_key(int index_no, int table_id_column_no,
const Object_id table_id,
int parent_partition_id_column_no,
const Object_id parent_partition_id)
: m_index_no(index_no),
m_table_id_column_no(table_id_column_no),
m_table_id(table_id),
m_parent_partition_id_column_no(parent_partition_id_column_no),
m_parent_partition_id(parent_partition_id) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_table_id_column_no;
Object_id m_table_id;
int m_parent_partition_id_column_no;
Object_id m_parent_partition_id;
};
///////////////////////////////////////////////////////////////////////////
// Range key to find rows using definer name.
class Definer_reference_range_key : public Object_key {
public:
Definer_reference_range_key(int index_no, int definer_column_no,
const String_type &definer)
: m_index_no(index_no),
m_definer_column_no(definer_column_no),
m_definer(definer) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_definer_column_no;
String_type m_definer;
};
///////////////////////////////////////////////////////////////////////////
// Range key to find rows using table type and definer name.
class View_definer_reference_range_key : public Object_key {
public:
View_definer_reference_range_key(int index_no, int table_type_column_no,
uint table_type, int definer_column_no,
const String_type &definer)
: m_index_no(index_no),
m_table_type_column_no(table_type_column_no),
m_table_type(table_type),
m_definer_column_no(definer_column_no),
m_definer(definer) {}
public:
Raw_key *create_access_key(Raw_table *db_table) const override;
String_type str() const override;
private:
int m_index_no;
int m_table_type_column_no;
uint m_table_type;
int m_definer_column_no;
String_type m_definer;
};
//////////////////////////////////////////////////////////////////////////////
} // namespace dd
#endif // DD__OBJECT_KEYS_INCLUDED
|