1/*****************************************************************************
2
3Copyright (c) 2006, 2016, Oracle and/or its affiliates. All Rights Reserved.
4Copyright (c) 2017, 2018, MariaDB Corporation.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free Software
8Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program; if not, write to the Free Software Foundation, Inc.,
1651 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17
18*****************************************************************************/
19
20/*******************************************************************//**
21@file include/ha_prototypes.h
22Prototypes for global functions in ha_innodb.cc that are called by
23InnoDB C code.
24
25NOTE: This header is intended to insulate InnoDB from SQL names and functions.
26Do not include any headers other than univ.i into this unless they are very
27simple headers.
28************************************************************************/
29
30#ifndef HA_INNODB_PROTOTYPES_H
31#define HA_INNODB_PROTOTYPES_H
32
33#include "univ.i"
34
35#ifndef UNIV_INNOCHECKSUM
36
37/* Forward declarations */
38class THD;
39
40// JAN: TODO missing features:
41#undef MYSQL_FT_INIT_EXT
42#undef MYSQL_PFS
43#undef MYSQL_RENAME_INDEX
44#undef MYSQL_STORE_FTS_DOC_ID
45
46/*******************************************************************//**
47Formats the raw data in "data" (in InnoDB on-disk format) that is of
48type DATA_(CHAR|VARCHAR|MYSQL|VARMYSQL) using "charset_coll" and writes
49the result to "buf". The result is converted to "system_charset_info".
50Not more than "buf_size" bytes are written to "buf".
51The result is always NUL-terminated (provided buf_size > 0) and the
52number of bytes that were written to "buf" is returned (including the
53terminating NUL).
54@return number of bytes that were written */
55ulint
56innobase_raw_format(
57/*================*/
58 const char* data, /*!< in: raw data */
59 ulint data_len, /*!< in: raw data length
60 in bytes */
61 ulint charset_coll, /*!< in: charset collation */
62 char* buf, /*!< out: output buffer */
63 ulint buf_size); /*!< in: output buffer size
64 in bytes */
65
66/*****************************************************************//**
67Invalidates the MySQL query cache for the table. */
68void
69innobase_invalidate_query_cache(
70/*============================*/
71 trx_t* trx, /*!< in: transaction which
72 modifies the table */
73 const char* full_name); /*!< in: concatenation of
74 database name, path separator,
75 table name, null char NUL;
76 NOTE that in Windows this is
77 always in LOWER CASE! */
78
79/** Quote a standard SQL identifier like tablespace, index or column name.
80@param[in] file output stream
81@param[in] trx InnoDB transaction, or NULL
82@param[in] id identifier to quote */
83void
84innobase_quote_identifier(
85 FILE* file,
86 trx_t* trx,
87 const char* id);
88
89/** Quote an standard SQL identifier like tablespace, index or column name.
90Return the string as an std:string object.
91@param[in] trx InnoDB transaction, or NULL
92@param[in] id identifier to quote
93@return a std::string with id properly quoted. */
94std::string
95innobase_quote_identifier(
96 trx_t* trx,
97 const char* id);
98
99/*****************************************************************//**
100Convert a table name to the MySQL system_charset_info (UTF-8).
101@return pointer to the end of buf */
102char*
103innobase_convert_name(
104/*==================*/
105 char* buf, /*!< out: buffer for converted identifier */
106 ulint buflen, /*!< in: length of buf, in bytes */
107 const char* id, /*!< in: table name to convert */
108 ulint idlen, /*!< in: length of id, in bytes */
109 THD* thd); /*!< in: MySQL connection thread, or NULL */
110
111/******************************************************************//**
112Returns true if the thread is the replication thread on the slave
113server. Used in srv_conc_enter_innodb() to determine if the thread
114should be allowed to enter InnoDB - the replication thread is treated
115differently than other threads. Also used in
116srv_conc_force_exit_innodb().
117@return true if thd is the replication thread */
118ibool
119thd_is_replication_slave_thread(
120/*============================*/
121 THD* thd); /*!< in: thread handle */
122
123/******************************************************************//**
124Returns true if the transaction this thread is processing has edited
125non-transactional tables. Used by the deadlock detector when deciding
126which transaction to rollback in case of a deadlock - we try to avoid
127rolling back transactions that have edited non-transactional tables.
128@return true if non-transactional tables have been edited */
129ibool
130thd_has_edited_nontrans_tables(
131/*===========================*/
132 THD* thd); /*!< in: thread handle */
133
134/**
135Get high resolution timestamp for the current query start time.
136
137@retval timestamp in microseconds precision
138*/
139unsigned long long thd_query_start_micro(const MYSQL_THD thd);
140
141/*************************************************************//**
142Prints info of a THD object (== user session thread) to the given file. */
143void
144innobase_mysql_print_thd(
145/*=====================*/
146 FILE* f, /*!< in: output stream */
147 THD* thd, /*!< in: pointer to a MySQL THD object */
148 uint max_query_len); /*!< in: max query length to print, or 0 to
149 use the default max length */
150
151/*****************************************************************//**
152Log code calls this whenever log has been written and/or flushed up
153to a new position. We use this to notify upper layer of a new commit
154checkpoint when necessary.*/
155UNIV_INTERN
156void
157innobase_mysql_log_notify(
158/*======================*/
159 ib_uint64_t flush_lsn); /*!< in: LSN flushed to disk */
160
161/** Converts a MySQL type to an InnoDB type. Note that this function returns
162the 'mtype' of InnoDB. InnoDB differentiates between MySQL's old <= 4.1
163VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'.
164@param[out] unsigned_flag DATA_UNSIGNED if an 'unsigned type';
165at least ENUM and SET, and unsigned integer types are 'unsigned types'
166@param[in] f MySQL Field
167@return DATA_BINARY, DATA_VARCHAR, ... */
168ulint
169get_innobase_type_from_mysql_type(
170 ulint* unsigned_flag,
171 const void* field);
172
173/******************************************************************//**
174Get the variable length bounds of the given character set. */
175void
176innobase_get_cset_width(
177/*====================*/
178 ulint cset, /*!< in: MySQL charset-collation code */
179 ulint* mbminlen, /*!< out: minimum length of a char (in bytes) */
180 ulint* mbmaxlen); /*!< out: maximum length of a char (in bytes) */
181
182/******************************************************************//**
183Compares NUL-terminated UTF-8 strings case insensitively.
184@return 0 if a=b, <0 if a<b, >1 if a>b */
185int
186innobase_strcasecmp(
187/*================*/
188 const char* a, /*!< in: first string to compare */
189 const char* b); /*!< in: second string to compare */
190
191/** Strip dir name from a full path name and return only the file name
192@param[in] path_name full path name
193@return file name or "null" if no file name */
194const char*
195innobase_basename(
196 const char* path_name);
197
198/******************************************************************//**
199Returns true if the thread is executing a SELECT statement.
200@return true if thd is executing SELECT */
201ibool
202thd_is_select(
203/*==========*/
204 const THD* thd); /*!< in: thread handle */
205
206/******************************************************************//**
207Converts an identifier to a table name. */
208void
209innobase_convert_from_table_id(
210/*===========================*/
211 CHARSET_INFO* cs, /*!< in: the 'from' character set */
212 char* to, /*!< out: converted identifier */
213 const char* from, /*!< in: identifier to convert */
214 ulint len); /*!< in: length of 'to', in bytes; should
215 be at least 5 * strlen(to) + 1 */
216/******************************************************************//**
217Converts an identifier to UTF-8. */
218void
219innobase_convert_from_id(
220/*=====================*/
221 CHARSET_INFO* cs, /*!< in: the 'from' character set */
222 char* to, /*!< out: converted identifier */
223 const char* from, /*!< in: identifier to convert */
224 ulint len); /*!< in: length of 'to', in bytes;
225 should be at least 3 * strlen(to) + 1 */
226/******************************************************************//**
227Makes all characters in a NUL-terminated UTF-8 string lower case. */
228void
229innobase_casedn_str(
230/*================*/
231 char* a); /*!< in/out: string to put in lower case */
232
233#ifdef WITH_WSREP
234UNIV_INTERN
235int
236wsrep_innobase_kill_one_trx(void * const thd_ptr,
237 const trx_t * const bf_trx,
238 trx_t *victim_trx,
239 ibool signal);
240ulint wsrep_innobase_mysql_sort(int mysql_type, uint charset_number,
241 unsigned char* str, unsigned int str_length,
242 unsigned int buf_length);
243#endif /* WITH_WSREP */
244
245/**********************************************************************//**
246Determines the connection character set.
247@return connection character set */
248CHARSET_INFO*
249innobase_get_charset(
250/*=================*/
251 THD* thd); /*!< in: MySQL thread handle */
252
253/** Determines the current SQL statement.
254Thread unsafe, can only be called from the thread owning the THD.
255@param[in] thd MySQL thread handle
256@param[out] length Length of the SQL statement
257@return SQL statement string */
258const char*
259innobase_get_stmt_unsafe(
260 THD* thd,
261 size_t* length);
262
263/** Determines the current SQL statement.
264Thread safe, can be called from any thread as the string is copied
265into the provided buffer.
266@param[in] thd MySQL thread handle
267@param[out] buf Buffer containing SQL statement
268@param[in] buflen Length of provided buffer
269@return Length of the SQL statement */
270size_t
271innobase_get_stmt_safe(
272 THD* thd,
273 char* buf,
274 size_t buflen);
275
276/******************************************************************//**
277This function is used to find the storage length in bytes of the first n
278characters for prefix indexes using a multibyte character set. The function
279finds charset information and returns length of prefix_len characters in the
280index field in bytes.
281@return number of bytes occupied by the first n characters */
282ulint
283innobase_get_at_most_n_mbchars(
284/*===========================*/
285 ulint charset_id, /*!< in: character set id */
286 ulint prefix_len, /*!< in: prefix length in bytes of the index
287 (this has to be divided by mbmaxlen to get the
288 number of CHARACTERS n in the prefix) */
289 ulint data_len, /*!< in: length of the string in bytes */
290 const char* str); /*!< in: character string */
291
292/** Get status of innodb_tmpdir.
293@param[in] thd thread handle, or NULL to query
294 the global innodb_tmpdir.
295@retval NULL if innodb_tmpdir="" */
296UNIV_INTERN
297const char*
298thd_innodb_tmpdir(
299 THD* thd);
300
301/******************************************************************//**
302Returns the lock wait timeout for the current connection.
303@return the lock wait timeout, in seconds */
304ulong
305thd_lock_wait_timeout(
306/*==================*/
307 THD* thd); /*!< in: thread handle, or NULL to query
308 the global innodb_lock_wait_timeout */
309/** Get status of innodb_tmpdir.
310@param[in] thd thread handle, or NULL to query
311 the global innodb_tmpdir.
312@retval NULL if innodb_tmpdir="" */
313const char*
314thd_innodb_tmpdir(
315 THD* thd);
316
317/**********************************************************************//**
318Get the current setting of the table_cache_size global parameter. We do
319a dirty read because for one there is no synchronization object and
320secondly there is little harm in doing so even if we get a torn read.
321@return SQL statement string */
322ulint
323innobase_get_table_cache_size(void);
324/*===============================*/
325
326/**********************************************************************//**
327Get the current setting of the lower_case_table_names global parameter from
328mysqld.cc. We do a dirty read because for one there is no synchronization
329object and secondly there is little harm in doing so even if we get a torn
330read.
331@return value of lower_case_table_names */
332ulint
333innobase_get_lower_case_table_names(void);
334/*=====================================*/
335
336/******************************************************************//**
337compare two character string case insensitively according to their charset. */
338int
339innobase_fts_text_case_cmp(
340/*=======================*/
341 const void* cs, /*!< in: Character set */
342 const void* p1, /*!< in: key */
343 const void* p2); /*!< in: node */
344
345/******************************************************************//**
346Returns true if transaction should be flagged as read-only.
347@return true if the thd is marked as read-only */
348bool
349thd_trx_is_read_only(
350/*=================*/
351 THD* thd); /*!< in/out: thread handle */
352
353/******************************************************************//**
354Check if the transaction is an auto-commit transaction. TRUE also
355implies that it is a SELECT (read-only) transaction.
356@return true if the transaction is an auto commit read-only transaction. */
357ibool
358thd_trx_is_auto_commit(
359/*===================*/
360 THD* thd); /*!< in: thread handle, or NULL */
361
362/******************************************************************//**
363Get the thread start time.
364@return the thread start time in seconds since the epoch. */
365ulint
366thd_start_time_in_secs(
367/*===================*/
368 THD* thd); /*!< in: thread handle, or NULL */
369
370/*****************************************************************//**
371A wrapper function of innobase_convert_name(), convert a table name
372to the MySQL system_charset_info (UTF-8) and quote it if needed.
373@return pointer to the end of buf */
374void
375innobase_format_name(
376/*==================*/
377 char* buf, /*!< out: buffer for converted identifier */
378 ulint buflen, /*!< in: length of buf, in bytes */
379 const char* name); /*!< in: table name to format */
380
381/** Corresponds to Sql_condition:enum_warning_level. */
382enum ib_log_level_t {
383 IB_LOG_LEVEL_INFO,
384 IB_LOG_LEVEL_WARN,
385 IB_LOG_LEVEL_ERROR,
386 IB_LOG_LEVEL_FATAL
387};
388
389/******************************************************************//**
390Use this when the args are first converted to a formatted string and then
391passed to the format string from errmsg-utf8.txt. The error message format
392must be: "Some string ... %s".
393
394Push a warning message to the client, it is a wrapper around:
395
396void push_warning_printf(
397 THD *thd, Sql_condition::enum_warning_level level,
398 uint code, const char *format, ...);
399*/
400void
401ib_errf(
402/*====*/
403 THD* thd, /*!< in/out: session */
404 ib_log_level_t level, /*!< in: warning level */
405 ib_uint32_t code, /*!< MySQL error code */
406 const char* format, /*!< printf format */
407 ...) /*!< Args */
408 MY_ATTRIBUTE((format(printf, 4, 5)));
409
410/******************************************************************//**
411Use this when the args are passed to the format string from
412errmsg-utf8.txt directly as is.
413
414Push a warning message to the client, it is a wrapper around:
415
416void push_warning_printf(
417 THD *thd, Sql_condition::enum_warning_level level,
418 uint code, const char *format, ...);
419*/
420void
421ib_senderrf(
422/*========*/
423 THD* thd, /*!< in/out: session */
424 ib_log_level_t level, /*!< in: warning level */
425 ib_uint32_t code, /*!< MySQL error code */
426 ...); /*!< Args */
427
428extern const char* TROUBLESHOOTING_MSG;
429extern const char* TROUBLESHOOT_DATADICT_MSG;
430extern const char* BUG_REPORT_MSG;
431extern const char* FORCE_RECOVERY_MSG;
432extern const char* ERROR_CREATING_MSG;
433extern const char* OPERATING_SYSTEM_ERROR_MSG;
434extern const char* FOREIGN_KEY_CONSTRAINTS_MSG;
435extern const char* SET_TRANSACTION_MSG;
436extern const char* INNODB_PARAMETERS_MSG;
437
438/******************************************************************//**
439Returns the NUL terminated value of glob_hostname.
440@return pointer to glob_hostname. */
441const char*
442server_get_hostname();
443/*=================*/
444
445/*********************************************************************//**
446Compute the next autoinc value.
447
448For MySQL replication the autoincrement values can be partitioned among
449the nodes. The offset is the start or origin of the autoincrement value
450for a particular node. For n nodes the increment will be n and the offset
451will be in the interval [1, n]. The formula tries to allocate the next
452value for a particular node.
453
454Note: This function is also called with increment set to the number of
455values we want to reserve for multi-value inserts e.g.,
456
457 INSERT INTO T VALUES(), (), ();
458
459innobase_next_autoinc() will be called with increment set to 3 where
460autoinc_lock_mode != TRADITIONAL because we want to reserve 3 values for
461the multi-value INSERT above.
462@return the next value */
463ulonglong
464innobase_next_autoinc(
465/*==================*/
466 ulonglong current, /*!< in: Current value */
467 ulonglong need, /*!< in: count of values needed */
468 ulonglong step, /*!< in: AUTOINC increment step */
469 ulonglong offset, /*!< in: AUTOINC offset */
470 ulonglong max_value) /*!< in: max value for type */
471 MY_ATTRIBUTE((pure, warn_unused_result));
472
473/**********************************************************************
474Converts an identifier from my_charset_filename to UTF-8 charset. */
475uint
476innobase_convert_to_system_charset(
477/*===============================*/
478 char* to, /* out: converted identifier */
479 const char* from, /* in: identifier to convert */
480 ulint len, /* in: length of 'to', in bytes */
481 uint* errors); /* out: error return */
482/**********************************************************************
483Check if the length of the identifier exceeds the maximum allowed.
484The input to this function is an identifier in charset my_charset_filename.
485return true when length of identifier is too long. */
486my_bool
487innobase_check_identifier_length(
488/*=============================*/
489 const char* id); /* in: identifier to check. it must belong
490 to charset my_charset_filename */
491
492/**********************************************************************
493Converts an identifier from my_charset_filename to UTF-8 charset. */
494uint
495innobase_convert_to_system_charset(
496/*===============================*/
497 char* to, /* out: converted identifier */
498 const char* from, /* in: identifier to convert */
499 ulint len, /* in: length of 'to', in bytes */
500 uint* errors); /* out: error return */
501
502/**********************************************************************
503Converts an identifier from my_charset_filename to UTF-8 charset. */
504uint
505innobase_convert_to_filename_charset(
506/*=================================*/
507 char* to, /* out: converted identifier */
508 const char* from, /* in: identifier to convert */
509 ulint len); /* in: length of 'to', in bytes */
510
511/********************************************************************//**
512Helper function to push warnings from InnoDB internals to SQL-layer. */
513UNIV_INTERN
514void
515ib_push_warning(
516 trx_t* trx, /*!< in: trx */
517 dberr_t error, /*!< in: error code to push as warning */
518 const char *format,/*!< in: warning message */
519 ...);
520
521/********************************************************************//**
522Helper function to push warnings from InnoDB internals to SQL-layer. */
523UNIV_INTERN
524void
525ib_push_warning(
526 void* ithd, /*!< in: thd */
527 dberr_t error, /*!< in: error code to push as warning */
528 const char *format,/*!< in: warning message */
529 ...);
530
531/*****************************************************************//**
532Normalizes a table name string. A normalized name consists of the
533database name catenated to '/' and table name. An example:
534test/mytable. On Windows normalization puts both the database name and the
535table name always to lower case if "set_lower_case" is set to TRUE. */
536void
537normalize_table_name_c_low(
538/*=======================*/
539 char* norm_name, /*!< out: normalized name as a
540 null-terminated string */
541 const char* name, /*!< in: table name string */
542 ibool set_lower_case); /*!< in: TRUE if we want to set
543 name to lower case */
544/*************************************************************//**
545InnoDB index push-down condition check defined in ha_innodb.cc
546@return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */
547
548#include <my_compare.h>
549
550ICP_RESULT
551innobase_index_cond(
552/*================*/
553 void* file) /*!< in/out: pointer to ha_innobase */
554 MY_ATTRIBUTE((warn_unused_result));
555
556/******************************************************************//**
557Gets information on the durability property requested by thread.
558Used when writing either a prepare or commit record to the log
559buffer.
560@return the durability property. */
561
562#include <dur_prop.h>
563
564enum durability_properties
565thd_requested_durability(
566/*=====================*/
567 const THD* thd) /*!< in: thread handle */
568 MY_ATTRIBUTE((warn_unused_result));
569
570/** Update the system variable with the given value of the InnoDB
571buffer pool size.
572@param[in] buf_pool_size given value of buffer pool size.*/
573void
574innodb_set_buf_pool_size(ulonglong buf_pool_size);
575
576/** Create a MYSQL_THD for a background thread and mark it as such.
577@param name thread info for SHOW PROCESSLIST
578@return new MYSQL_THD */
579MYSQL_THD
580innobase_create_background_thd(const char* name);
581
582/** Destroy a background purge thread THD.
583@param[in] thd MYSQL_THD to destroy */
584void
585innobase_destroy_background_thd(MYSQL_THD);
586
587/** Close opened tables, free memory, delete items for a MYSQL_THD.
588@param[in] thd MYSQL_THD to reset */
589void
590innobase_reset_background_thd(MYSQL_THD);
591
592#endif /* !UNIV_INNOCHECKSUM */
593#endif /* HA_INNODB_PROTOTYPES_H */
594