The world's most popular open source database
00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 00018 /* The old structures from unireg */ 00019 00020 struct st_table; 00021 class Field; 00022 00023 typedef struct st_date_time_format { 00024 uchar positions[8]; 00025 char time_separator; /* Separator between hour and minute */ 00026 uint flag; /* For future */ 00027 LEX_STRING format; 00028 } DATE_TIME_FORMAT; 00029 00030 00031 typedef struct st_keyfile_info { /* used with ha_info() */ 00032 byte ref[MAX_REFLENGTH]; /* Pointer to current row */ 00033 byte dupp_ref[MAX_REFLENGTH]; /* Pointer to dupp row */ 00034 uint ref_length; /* Length of ref (1-8) */ 00035 uint block_size; /* index block size */ 00036 File filenr; /* (uniq) filenr for table */ 00037 ha_rows records; /* Records i datafilen */ 00038 ha_rows deleted; /* Deleted records */ 00039 ulonglong data_file_length; /* Length off data file */ 00040 ulonglong max_data_file_length; /* Length off data file */ 00041 ulonglong index_file_length; 00042 ulonglong max_index_file_length; 00043 ulonglong delete_length; /* Free bytes */ 00044 ulonglong auto_increment_value; 00045 int errkey,sortkey; /* Last errorkey and sorted by */ 00046 time_t create_time; /* When table was created */ 00047 time_t check_time; 00048 time_t update_time; 00049 ulong mean_rec_length; /* physical reclength */ 00050 } KEYFILE_INFO; 00051 00052 00053 typedef struct st_key_part_info { /* Info about a key part */ 00054 Field *field; 00055 uint offset; /* offset in record (from 0) */ 00056 uint null_offset; /* Offset to null_bit in record */ 00057 uint16 length; /* Length of keypart value in bytes */ 00058 /* 00059 Number of bytes required to store the keypart value. This may be 00060 different from the "length" field as it also counts 00061 - possible NULL-flag byte (see HA_KEY_NULL_LENGTH) 00062 - possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length. 00063 */ 00064 uint16 store_length; 00065 uint16 key_type; 00066 uint16 fieldnr; /* Fieldnum in UNIREG */ 00067 uint16 key_part_flag; /* 0 or HA_REVERSE_SORT */ 00068 uint8 type; 00069 uint8 null_bit; /* Position to null_bit */ 00070 } KEY_PART_INFO ; 00071 00072 00073 typedef struct st_key { 00074 uint key_length; /* Tot length of key */ 00075 uint flags; /* dupp key and pack flags */ 00076 uint key_parts; /* How many key_parts */ 00077 uint extra_length; 00078 uint usable_key_parts; /* Should normally be = key_parts */ 00079 uint block_size; 00080 enum ha_key_alg algorithm; 00081 /* 00082 Note that parser is used when the table is opened for use, and 00083 parser_name is used when the table is being created. 00084 */ 00085 union 00086 { 00087 struct st_plugin_int *parser; /* Fulltext [pre]parser */ 00088 LEX_STRING *parser_name; /* Fulltext [pre]parser name */ 00089 }; 00090 KEY_PART_INFO *key_part; 00091 char *name; /* Name of key */ 00092 /* 00093 Array of AVG(#records with the same field value) for 1st ... Nth key part. 00094 0 means 'not known'. 00095 For temporary heap tables this member is NULL. 00096 */ 00097 ulong *rec_per_key; 00098 union { 00099 int bdb_return_if_eq; 00100 } handler; 00101 struct st_table *table; 00102 } KEY; 00103 00104 00105 struct st_join_table; 00106 00107 typedef struct st_reginfo { /* Extra info about reg */ 00108 struct st_join_table *join_tab; /* Used by SELECT() */ 00109 enum thr_lock_type lock_type; /* How database is used */ 00110 bool not_exists_optimize; 00111 bool impossible_range; 00112 } REGINFO; 00113 00114 00115 struct st_read_record; /* For referense later */ 00116 class SQL_SELECT; 00117 class THD; 00118 class handler; 00119 00120 typedef struct st_read_record { /* Parameter to read_record */ 00121 struct st_table *table; /* Head-form */ 00122 handler *file; 00123 struct st_table **forms; /* head and ref forms */ 00124 int (*read_record)(struct st_read_record *); 00125 THD *thd; 00126 SQL_SELECT *select; 00127 uint cache_records; 00128 uint ref_length,struct_length,reclength,rec_cache_size,error_offset; 00129 uint index; 00130 byte *ref_pos; /* pointer to form->refpos */ 00131 byte *record; 00132 byte *rec_buf; /* to read field values after filesort */ 00133 byte *cache,*cache_pos,*cache_end,*read_positions; 00134 IO_CACHE *io_cache; 00135 bool print_error, ignore_not_found_rows; 00136 } READ_RECORD; 00137 00138 00139 /* 00140 Originally MySQL used TIME structure inside server only, but since 00141 4.1 it's exported to user in the new client API. Define aliases for 00142 new names to keep existing code simple. 00143 */ 00144 00145 typedef struct st_mysql_time TIME; 00146 typedef enum enum_mysql_timestamp_type timestamp_type; 00147 00148 00149 typedef struct { 00150 ulong year,month,day,hour; 00151 ulonglong minute,second,second_part; 00152 bool neg; 00153 } INTERVAL; 00154 00155 00156 typedef struct st_known_date_time_format { 00157 const char *format_name; 00158 const char *date_format; 00159 const char *datetime_format; 00160 const char *time_format; 00161 } KNOWN_DATE_TIME_FORMAT; 00162 00163 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED}; 00164 00165 extern const char *show_comp_option_name[]; 00166 00167 typedef int *(*update_var)(THD *, struct st_mysql_show_var *); 00168 00169 typedef struct st_lex_user { 00170 LEX_STRING user, host, password; 00171 } LEX_USER; 00172 00173 /* 00174 This structure specifies the maximum amount of resources which 00175 can be consumed by each account. Zero value of a member means 00176 there is no limit. 00177 */ 00178 typedef struct user_resources { 00179 /* Maximum number of queries/statements per hour. */ 00180 uint questions; 00181 /* 00182 Maximum number of updating statements per hour (which statements are 00183 updating is defined by sql_command_flags array). 00184 */ 00185 uint updates; 00186 /* Maximum number of connections established per hour. */ 00187 uint conn_per_hour; 00188 /* Maximum number of concurrent connections. */ 00189 uint user_conn; 00190 /* 00191 Values of this enum and specified_limits member are used by the 00192 parser to store which user limits were specified in GRANT statement. 00193 */ 00194 enum {QUERIES_PER_HOUR= 1, UPDATES_PER_HOUR= 2, CONNECTIONS_PER_HOUR= 4, 00195 USER_CONNECTIONS= 8}; 00196 uint specified_limits; 00197 } USER_RESOURCES; 00198 00199 00200 /* 00201 This structure is used for counting resources consumed and for checking 00202 them against specified user limits. 00203 */ 00204 typedef struct user_conn { 00205 /* 00206 Pointer to user+host key (pair separated by '\0') defining the entity 00207 for which resources are counted (By default it is user account thus 00208 priv_user/priv_host pair is used. If --old-style-user-limits option 00209 is enabled, resources are counted for each user+host separately). 00210 */ 00211 char *user; 00212 /* Pointer to host part of the key. */ 00213 char *host; 00214 /* Total length of the key. */ 00215 uint len; 00216 /* Current amount of concurrent connections for this account. */ 00217 uint connections; 00218 /* 00219 Current number of connections per hour, number of updating statements 00220 per hour and total number of statements per hour for this account. 00221 */ 00222 uint conn_per_hour, updates, questions; 00223 /* Maximum amount of resources which account is allowed to consume. */ 00224 USER_RESOURCES user_resources; 00225 /* 00226 The moment of time when per hour counters were reset last time 00227 (i.e. start of "hour" for conn_per_hour, updates, questions counters). 00228 */ 00229 time_t intime; 00230 } USER_CONN; 00231 00232 /* Bits in form->update */ 00233 #define REG_MAKE_DUPP 1 /* Make a copy of record when read */ 00234 #define REG_NEW_RECORD 2 /* Write a new record if not found */ 00235 #define REG_UPDATE 4 /* Uppdate record */ 00236 #define REG_DELETE 8 /* Delete found record */ 00237 #define REG_PROG 16 /* User is updating database */ 00238 #define REG_CLEAR_AFTER_WRITE 32 00239 #define REG_MAY_BE_UPDATED 64 00240 #define REG_AUTO_UPDATE 64 /* Used in D-forms for scroll-tables */ 00241 #define REG_OVERWRITE 128 00242 #define REG_SKIP_DUP 256 00243 00244 /* Bits in form->status */ 00245 #define STATUS_NO_RECORD (1+2) /* Record isn't usably */ 00246 #define STATUS_GARBAGE 1 00247 #define STATUS_NOT_FOUND 2 /* No record in database when needed */ 00248 #define STATUS_NO_PARENT 4 /* Parent record wasn't found */ 00249 #define STATUS_NOT_READ 8 /* Record isn't read */ 00250 #define STATUS_UPDATED 16 /* Record is updated by formula */ 00251 #define STATUS_NULL_ROW 32 /* table->null_row is set */ 00252 #define STATUS_DELETED 64 00253 00254 /* 00255 Such interval is "discrete": it is the set of 00256 { auto_inc_interval_min + k * increment, 00257 0 <= k <= (auto_inc_interval_values-1) } 00258 Where "increment" is maintained separately by the user of this class (and is 00259 currently only thd->variables.auto_increment_increment). 00260 It mustn't derive from Sql_alloc, because SET INSERT_ID needs to 00261 allocate memory which must stay allocated for use by the next statement. 00262 */ 00263 class Discrete_interval { 00264 private: 00265 ulonglong interval_min; 00266 ulonglong interval_values; 00267 ulonglong interval_max; // excluded bound. Redundant. 00268 public: 00269 Discrete_interval *next; // used when linked into Discrete_intervals_list 00270 void replace(ulonglong start, ulonglong val, ulonglong incr) 00271 { 00272 interval_min= start; 00273 interval_values= val; 00274 interval_max= (val == ULONGLONG_MAX) ? val : start + val * incr; 00275 } 00276 Discrete_interval(ulonglong start, ulonglong val, ulonglong incr) : 00277 next(NULL) { replace(start, val, incr); }; 00278 Discrete_interval() : next(NULL) { replace(0, 0, 0); }; 00279 ulonglong minimum() const { return interval_min; }; 00280 ulonglong values() const { return interval_values; }; 00281 ulonglong maximum() const { return interval_max; }; 00282 /* 00283 If appending [3,5] to [1,2], we merge both in [1,5] (they should have the 00284 same increment for that, user of the class has to ensure that). That is 00285 just a space optimization. Returns 0 if merge succeeded. 00286 */ 00287 bool merge_if_contiguous(ulonglong start, ulonglong val, ulonglong incr) 00288 { 00289 if (interval_max == start) 00290 { 00291 if (val == ULONGLONG_MAX) 00292 { 00293 interval_values= interval_max= val; 00294 } 00295 else 00296 { 00297 interval_values+= val; 00298 interval_max= start + val * incr; 00299 } 00300 return 0; 00301 } 00302 return 1; 00303 }; 00304 }; 00305 00306 /* List of Discrete_interval objects */ 00307 class Discrete_intervals_list { 00308 private: 00309 Discrete_interval *head; 00310 Discrete_interval *tail; 00311 /* 00312 When many intervals are provided at the beginning of the execution of a 00313 statement (in a replication slave or SET INSERT_ID), "current" points to 00314 the interval being consumed by the thread now (so "current" goes from 00315 "head" to "tail" then to NULL). 00316 */ 00317 Discrete_interval *current; 00318 uint elements; // number of elements 00319 public: 00320 Discrete_intervals_list() : head(NULL), current(NULL), elements(0) {}; 00321 void empty_no_free() 00322 { 00323 head= current= NULL; 00324 elements= 0; 00325 } 00326 void empty() 00327 { 00328 for (Discrete_interval *i= head; i;) 00329 { 00330 Discrete_interval *next= i->next; 00331 delete i; 00332 i= next; 00333 } 00334 empty_no_free(); 00335 } 00336 const Discrete_interval* get_next() 00337 { 00338 Discrete_interval *tmp= current; 00339 if (current != NULL) 00340 current= current->next; 00341 return tmp; 00342 } 00343 ~Discrete_intervals_list() { empty(); }; 00344 bool append(ulonglong start, ulonglong val, ulonglong incr); 00345 ulonglong minimum() const { return (head ? head->minimum() : 0); }; 00346 ulonglong maximum() const { return (head ? tail->maximum() : 0); }; 00347 uint nb_elements() const { return elements; } 00348 };
1.4.7

