My Project
structs.h
00001 #ifndef STRUCTS_INCLUDED
00002 #define STRUCTS_INCLUDED
00003 
00004 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; version 2 of the License.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00018 
00019 
00020 
00021 /* The old structures from unireg */
00022 
00023 #include "sql_plugin.h"                         /* plugin_ref */
00024 #include "sql_const.h"                          /* MAX_REFLENGTH */
00025 #include "my_time.h"                   /* enum_mysql_timestamp_type */
00026 #include "thr_lock.h"                  /* thr_lock_type */
00027 #include "my_base.h"                   /* ha_rows, ha_key_alg */
00028 
00029 struct TABLE;
00030 class Field;
00031 
00032 class THD;
00033 
00034 typedef struct st_date_time_format {
00035   uchar positions[8];
00036   char  time_separator;                 /* Separator between hour and minute */
00037   uint flag;                            /* For future */
00038   LEX_STRING format;
00039 } DATE_TIME_FORMAT;
00040 
00041 
00042 typedef struct st_keyfile_info {        /* used with ha_info() */
00043   uchar ref[MAX_REFLENGTH];             /* Pointer to current row */
00044   uchar dupp_ref[MAX_REFLENGTH];        /* Pointer to dupp row */
00045   uint ref_length;                      /* Length of ref (1-8) */
00046   uint block_size;                      /* index block size */
00047   File filenr;                          /* (uniq) filenr for table */
00048   ha_rows records;                      /* Records i datafilen */
00049   ha_rows deleted;                      /* Deleted records */
00050   ulonglong data_file_length;           /* Length off data file */
00051   ulonglong max_data_file_length;       /* Length off data file */
00052   ulonglong index_file_length;
00053   ulonglong max_index_file_length;
00054   ulonglong delete_length;              /* Free bytes */
00055   ulonglong auto_increment_value;
00056   int errkey,sortkey;                   /* Last errorkey and sorted by */
00057   time_t create_time;                   /* When table was created */
00058   time_t check_time;
00059   time_t update_time;
00060   ulong mean_rec_length;                /* physical reclength */
00061 } KEYFILE_INFO;
00062 
00063 
00064 class KEY_PART_INFO {   /* Info about a key part */
00065 public:
00066   Field *field;
00067   uint  offset;                         /* offset in record (from 0) */
00068   uint  null_offset;                    /* Offset to null_bit in record */
00069   /* Length of key part in bytes, excluding NULL flag and length bytes */
00070   uint16 length;
00071   /*
00072     Number of bytes required to store the keypart value. This may be
00073     different from the "length" field as it also counts
00074      - possible NULL-flag byte (see HA_KEY_NULL_LENGTH)
00075      - possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length.
00076   */
00077   uint16 store_length;
00078   uint16 key_type;
00079   uint16 fieldnr;                       /* Fieldnum in UNIREG */
00080   uint16 key_part_flag;                 /* 0 or HA_REVERSE_SORT */
00081   uint8 type;
00082   uint8 null_bit;                       /* Position to null_bit */
00083   void init_from_field(Field *fld);     
00084   void init_flags();                    
00085 };
00086 
00087 
00088 typedef struct st_key {
00090   uint  key_length;
00092   ulong flags;
00094   ulong actual_flags;
00096   uint  user_defined_key_parts;
00098   uint  actual_key_parts;
00103   uint  unused_key_parts;
00105   uint  usable_key_parts;
00106   uint  block_size;
00107   enum  ha_key_alg algorithm;
00112   union
00113   {
00115     plugin_ref parser;
00117     LEX_STRING *parser_name;
00118   };
00119   KEY_PART_INFO *key_part;
00121   char  *name;
00127   ulong *rec_per_key;
00128   union {
00129     int  bdb_return_if_eq;
00130   } handler;
00131   TABLE *table;
00132   LEX_STRING comment;
00133 } KEY;
00134 
00135 
00136 struct st_join_table;
00137 
00138 typedef struct st_reginfo {             /* Extra info about reg */
00139   struct st_join_table *join_tab;       /* Used by SELECT() */
00140   enum thr_lock_type lock_type;         /* How database is used */
00141   bool not_exists_optimize;
00142   /*
00143     TRUE <=> range optimizer found that there is no rows satisfying
00144     table conditions.
00145   */
00146   bool impossible_range;
00147 } REGINFO;
00148 
00149 
00150 /*
00151   Originally MySQL used MYSQL_TIME structure inside server only, but since
00152   4.1 it's exported to user in the new client API. Define aliases for
00153   new names to keep existing code simple.
00154 */
00155 
00156 typedef enum enum_mysql_timestamp_type timestamp_type;
00157 
00158 
00159 typedef struct {
00160   ulong year,month,day,hour;
00161   ulonglong minute,second,second_part;
00162   bool neg;
00163 } INTERVAL;
00164 
00165 
00166 typedef struct st_known_date_time_format {
00167   const char *format_name;
00168   const char *date_format;
00169   const char *datetime_format;
00170   const char *time_format;
00171 } KNOWN_DATE_TIME_FORMAT;
00172 
00173 extern const char *show_comp_option_name[];
00174 
00175 typedef int *(*update_var)(THD *, struct st_mysql_show_var *);
00176 
00177 typedef struct  st_lex_user {
00178   LEX_STRING user, host, password, plugin, auth;
00179   bool uses_identified_by_clause;
00180   bool uses_identified_with_clause;
00181   bool uses_authentication_string_clause;
00182   bool uses_identified_by_password_clause;
00183 } LEX_USER;
00184 
00185 /*
00186   This structure specifies the maximum amount of resources which
00187   can be consumed by each account. Zero value of a member means
00188   there is no limit.
00189 */
00190 typedef struct user_resources {
00191   /* Maximum number of queries/statements per hour. */
00192   uint questions;
00193   /*
00194      Maximum number of updating statements per hour (which statements are
00195      updating is defined by sql_command_flags array).
00196   */
00197   uint updates;
00198   /* Maximum number of connections established per hour. */
00199   uint conn_per_hour;
00200   /* Maximum number of concurrent connections. */
00201   uint user_conn;
00202   /*
00203      Values of this enum and specified_limits member are used by the
00204      parser to store which user limits were specified in GRANT statement.
00205   */
00206   enum {QUERIES_PER_HOUR= 1, UPDATES_PER_HOUR= 2, CONNECTIONS_PER_HOUR= 4,
00207         USER_CONNECTIONS= 8};
00208   uint specified_limits;
00209 } USER_RESOURCES;
00210 
00211 
00212 /*
00213   This structure is used for counting resources consumed and for checking
00214   them against specified user limits.
00215 */
00216 typedef struct  user_conn {
00217   /*
00218      Pointer to user+host key (pair separated by '\0') defining the entity
00219      for which resources are counted (By default it is user account thus
00220      priv_user/priv_host pair is used. If --old-style-user-limits option
00221      is enabled, resources are counted for each user+host separately).
00222   */
00223   char *user;
00224   /* Pointer to host part of the key. */
00225   char *host;
00230   ulonglong reset_utime;
00231   /* Total length of the key. */
00232   uint len;
00233   /* Current amount of concurrent connections for this account. */
00234   uint connections;
00235   /*
00236      Current number of connections per hour, number of updating statements
00237      per hour and total number of statements per hour for this account.
00238   */
00239   uint conn_per_hour, updates, questions;
00240   /* Maximum amount of resources which account is allowed to consume. */
00241   USER_RESOURCES user_resources;
00242 } USER_CONN;
00243 
00244         /* Bits in form->update */
00245 #define REG_MAKE_DUPP           1       /* Make a copy of record when read */
00246 #define REG_NEW_RECORD          2       /* Write a new record if not found */
00247 #define REG_UPDATE              4       /* Uppdate record */
00248 #define REG_DELETE              8       /* Delete found record */
00249 #define REG_PROG                16      /* User is updating database */
00250 #define REG_CLEAR_AFTER_WRITE   32
00251 #define REG_MAY_BE_UPDATED      64
00252 #define REG_AUTO_UPDATE         64      /* Used in D-forms for scroll-tables */
00253 #define REG_OVERWRITE           128
00254 #define REG_SKIP_DUP            256
00255 
00263 #define STATUS_GARBAGE          1
00264 
00268 #define STATUS_NOT_FOUND        2
00269 
00270 #define STATUS_UPDATED          16
00271 
00275 #define STATUS_NULL_ROW         32
00276 
00277 #define STATUS_DELETED          64
00278 
00279 /*
00280   Such interval is "discrete": it is the set of
00281   { auto_inc_interval_min + k * increment,
00282     0 <= k <= (auto_inc_interval_values-1) }
00283   Where "increment" is maintained separately by the user of this class (and is
00284   currently only thd->variables.auto_increment_increment).
00285   It mustn't derive from Sql_alloc, because SET INSERT_ID needs to
00286   allocate memory which must stay allocated for use by the next statement.
00287 */
00288 class Discrete_interval {
00289 private:
00290   ulonglong interval_min;
00291   ulonglong interval_values;
00292   ulonglong  interval_max;    // excluded bound. Redundant.
00293 public:
00294   Discrete_interval *next;    // used when linked into Discrete_intervals_list
00295 
00297   bool in_range(const ulonglong value) const
00298   {
00299     return  ((value >= interval_min) && (value < interval_max));
00300   }
00301 
00302   void replace(ulonglong start, ulonglong val, ulonglong incr)
00303   {
00304     interval_min=    start;
00305     interval_values= val;
00306     interval_max=    (val == ULONGLONG_MAX) ? val : start + val * incr;
00307   }
00308   Discrete_interval(ulonglong start, ulonglong val, ulonglong incr) :
00309     next(NULL) { replace(start, val, incr); };
00310   Discrete_interval() : next(NULL) { replace(0, 0, 0); };
00311   ulonglong minimum() const { return interval_min;    };
00312   ulonglong values()  const { return interval_values; };
00313   ulonglong maximum() const { return interval_max;    };
00314   /*
00315     If appending [3,5] to [1,2], we merge both in [1,5] (they should have the
00316     same increment for that, user of the class has to ensure that). That is
00317     just a space optimization. Returns 0 if merge succeeded.
00318   */
00319   bool merge_if_contiguous(ulonglong start, ulonglong val, ulonglong incr)
00320   {
00321     if (interval_max == start)
00322     {
00323       if (val == ULONGLONG_MAX)
00324       {
00325         interval_values=   interval_max= val;
00326       }
00327       else
00328       {
00329         interval_values+=  val;
00330         interval_max=      start + val * incr;
00331       }
00332       return 0;
00333     }
00334     return 1;
00335   };
00336 };
00337 
00339 class Discrete_intervals_list {
00340 
00351 #define DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT 1
00352 
00353 private:
00358   Discrete_interval        first_interval;
00359   Discrete_interval        *head;
00360   Discrete_interval        *tail;
00367   Discrete_interval        *current;
00368   uint                  elements;               
00369   void operator=(Discrete_intervals_list &);    // prevent use of this
00370   bool append(Discrete_interval *new_interval)
00371   {
00372     if (unlikely(new_interval == NULL))
00373       return true;
00374     DBUG_PRINT("info",("adding new auto_increment interval"));
00375     if (head == NULL)
00376       head= current= new_interval;
00377     else
00378       tail->next= new_interval;
00379     tail= new_interval;
00380     elements++;
00381     return false;
00382   }
00383   void copy_shallow(const Discrete_intervals_list *other)
00384   {
00385     const Discrete_interval *o_first_interval= &other->first_interval;
00386     first_interval= other->first_interval;
00387     head= other->head == o_first_interval ? &first_interval : other->head;
00388     tail= other->tail == o_first_interval ? &first_interval : other->tail;
00389     current=
00390       other->current == o_first_interval ? &first_interval : other->current;
00391     elements= other->elements;
00392   }
00393   Discrete_intervals_list(const Discrete_intervals_list &other)
00394   { copy_shallow(&other); }
00395 
00396 public:
00397   Discrete_intervals_list()
00398     : head(NULL), tail(NULL), current(NULL), elements(0) {}
00399   void empty()
00400   {
00401     if (head)
00402     {
00403       // first element, not on heap, should not be delete-d; start with next:
00404       for (Discrete_interval *i= head->next; i;)
00405       {
00406 #ifdef DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT
00407         DBUG_ASSERT(0);
00408 #endif
00409         Discrete_interval *next= i->next;
00410         delete i;
00411         i= next;
00412       }
00413     }
00414     head= tail= current= NULL;
00415     elements= 0;
00416   }
00417   void swap(Discrete_intervals_list *other)
00418   {
00419     const Discrete_intervals_list tmp(*other);
00420     other->copy_shallow(this);
00421     copy_shallow(&tmp);
00422   }
00423   const Discrete_interval *get_next()
00424   {
00425     const Discrete_interval *tmp= current;
00426     if (current != NULL)
00427       current= current->next;
00428     return tmp;
00429   }
00430   ~Discrete_intervals_list() { empty(); };
00440   bool append(ulonglong start, ulonglong val, ulonglong incr)
00441   {
00442     // If there are no intervals, add one.
00443     if (head == NULL)
00444     {
00445       first_interval.replace(start, val, incr);
00446       return append(&first_interval);
00447     }
00448     // If this interval can be merged with previous, do that.
00449     if (tail->merge_if_contiguous(start, val, incr) == 0)
00450       return false;
00451     // If this interval cannot be merged, append it.
00452 #ifdef DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT
00453     /*
00454       We cannot create yet another interval as we already contain one. This
00455       situation can happen. Assume innodb_autoinc_lock_mode>=1 and
00456        CREATE TABLE T(A INT AUTO_INCREMENT PRIMARY KEY) ENGINE=INNODB;
00457        INSERT INTO T VALUES (NULL),(NULL),(1025),(NULL);
00458       Then InnoDB will reserve [1,4] (because of 4 rows) then
00459       [1026,1026]. Only the first interval is important for
00460       statement-based binary logging as it tells the starting point. So we
00461       ignore the second interval:
00462     */
00463     return false;
00464 #else
00465     return append(new Discrete_interval(start, val, incr));
00466 #endif
00467   }
00468   ulonglong minimum()     const { return (head ? head->minimum() : 0); };
00469   ulonglong maximum()     const { return (head ? tail->maximum() : 0); };
00470   uint      nb_elements() const { return elements; }
00471 };
00472 
00473 #endif /* STRUCTS_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines