D.S

dev.mysql.com

MySQL: sql/key_spec.h Source File

MySQL: sql/key_spec.h Source File MySQL  8.0.0 Source Code Documentation Main Page Related Pages Modules Namespaces Classes Files File List File Members key_spec.h Go to the documentation of this file. 1 /* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 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 as published by 5  the Free Software Foundation; version 2 of the License. 6  7  This program is distributed in the hope that it will be useful, 8  but WITHOUT ANY WARRANTY; without even the implied warranty of 9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10  GNU General Public License for more details. 11  12  You should have received a copy of the GNU General Public License 13  along with this program; if not, write to the Free Software 14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15  16 #ifndef KEY_SPEC_INCLUDED 17 #define KEY_SPEC_INCLUDED 18  19 #include " my_global.h " 20 #include " m_string.h " 21 #include " my_base.h " 22 #include " mem_root_array.h " 23 #include " sql_alloc.h " 24 #include " sql_list.h " 25  26 class Create_field ; 27  28  29  enum keytype { 30   KEYTYPE_PRIMARY , 31   KEYTYPE_UNIQUE , 32   KEYTYPE_MULTIPLE , 33   KEYTYPE_FULLTEXT , 34   KEYTYPE_SPATIAL , 35   KEYTYPE_FOREIGN 36 }; 37  38  enum fk_option { 39   FK_OPTION_UNDEF , 40   FK_OPTION_RESTRICT , 41   FK_OPTION_CASCADE , 42   FK_OPTION_SET_NULL , 43   FK_OPTION_NO_ACTION , 44   FK_OPTION_DEFAULT 45 }; 46  47  enum fk_match_opt { 48   FK_MATCH_UNDEF , 49   FK_MATCH_FULL , 50   FK_MATCH_PARTIAL , 51   FK_MATCH_SIMPLE 52 }; 53  54  55  class KEY_CREATE_INFO 56 { 57 public: 58   enum ha_key_alg algorithm = HA_KEY_ALG_SE_SPECIFIC ; 59  /** 60  A flag which indicates that index algorithm was explicitly specified 61  by user. 62  */ 63   bool is_algorithm_explicit = false; 64   ulong block_size = 0; 65   LEX_CSTRING parser_name = { NullS , 0}; 66   LEX_CSTRING comment = { NullS , 0}; 67   bool is_visible = true; 68  69  KEY_CREATE_INFO ()= default; 70  71   explicit KEY_CREATE_INFO (bool is_visible_arg) : is_visible(is_visible_arg) {} 72 }; 73  74  75 extern KEY_CREATE_INFO default_key_create_info ; 76  77  78  class Key_part_spec : public Sql_alloc 79 { 80 public: 81   const LEX_CSTRING field_name ; 82   const uint length ; 83  84   Key_part_spec (const LEX_CSTRING &name, uint len) 85  : field_name(name), length(len) 86  {} 87  bool operator== (const Key_part_spec & other) const; 88 }; 89  90  91  class Key_spec : public Sql_alloc 92 { 93 public: 94   const keytype type ; 95   const KEY_CREATE_INFO key_create_info ; 96   Mem_root_array<const Key_part_spec*> columns ; 97   const LEX_CSTRING name ; 98   const bool generated ; 99  /** 100  A flag to determine if we will check for duplicate indexes. 101  This typically means that the key information was specified 102  directly by the user (set by the parser) or a column 103  associated with it was dropped. 104  */ 105   const bool check_for_duplicate_indexes ; 106  107   Key_spec ( MEM_ROOT * mem_root , 108  keytype type_par, 109  const LEX_CSTRING &name_arg, 110  const KEY_CREATE_INFO *key_info_arg, 111  bool generated_arg, 112  bool check_for_duplicate_indexes_arg, 113  List<Key_part_spec> &cols) 114  :type(type_par), 115  key_create_info(*key_info_arg), 116  columns(mem_root), 117  name(name_arg), 118  generated(generated_arg), 119  check_for_duplicate_indexes(check_for_duplicate_indexes_arg) 120  { 121  columns. reserve (cols. elements ); 122  List_iterator<Key_part_spec> it(cols); 123  const Key_part_spec *column; 124  while ((column= it++)) 125  columns. push_back (column); 126  } 127  128   virtual ~Key_spec () {} 129 }; 130  131  132  class Foreign_key_spec : public Key_spec 133 { 134 public: 135   const LEX_CSTRING ref_db ; 136   const LEX_CSTRING ref_table ; 137   Mem_root_array<const Key_part_spec*> ref_columns ; 138   const fk_option delete_opt ; 139   const fk_option update_opt ; 140   const fk_match_opt match_opt ; 141  142   Foreign_key_spec ( MEM_ROOT * mem_root , 143  const LEX_CSTRING &name_arg, 144  List<Key_part_spec> cols, 145  const LEX_CSTRING &ref_db_arg, 146  const LEX_CSTRING &ref_table_arg, 147  List<Key_part_spec> *ref_cols, 148  fk_option delete_opt_arg, 149  fk_option update_opt_arg, 150  fk_match_opt match_opt_arg) 151  : Key_spec (mem_root, KEYTYPE_FOREIGN , name_arg, 152  &default_key_create_info, false, 153  false, // We don't check for duplicate FKs. 154  cols), 155  ref_db(ref_db_arg), 156  ref_table(ref_table_arg), 157  ref_columns(mem_root), 158  delete_opt(delete_opt_arg), 159  update_opt(update_opt_arg), 160  match_opt(match_opt_arg) 161  { 162  if (ref_cols) 163  { 164  ref_columns. reserve (ref_cols-> elements ); 165  List_iterator<Key_part_spec> it(*ref_cols); 166  const Key_part_spec *ref_column; 167  while ((ref_column= it++)) 168  ref_columns. push_back (ref_column); 169  } 170