MySQL 5.6.14 Source Code Document
|
#include "univ.i"
#include "data0type.h"
#include "data0types.h"
#include "dict0types.h"
#include "hash0hash.h"
#include "mem0mem.h"
#include "rem0types.h"
#include "row0types.h"
#include "trx0types.h"
#include "ut0vec.h"
#include "ut0rbt.h"
#include "ut0wqueue.h"
#include "que0types.h"
#include "ft_global.h"
Go to the source code of this file.
Classes | |
struct | fts_trx_t |
struct | fts_savepoint_t |
struct | fts_trx_table_t |
struct | fts_trx_row_t |
struct | fts_doc_ids_t |
struct | fts_string_t |
struct | fts_ranking_t |
struct | fts_result_t |
struct | fts_table_t |
struct | fts_t |
Macros | |
#define | FTS_NULL_DOC_ID 0 |
#define | FTS_DOC_ID_COL_NAME "FTS_DOC_ID" |
#define | FTS_DOC_ID_INDEX_NAME "FTS_DOC_ID_INDEX" |
#define | FTS_DOC_ID_INDEX_NAME_LEN 16 |
#define | FTS_DOC_ID_LEN 8 |
#define | FTS_NUM_FIELDS_SORT 3 |
#define | MAX_DOC_ID_OPT_VAL 1073741824 |
#define | FTS_DOC_ID_FORMAT IB_ID_FMT |
#define | fts_write_doc_id(d, s) mach_write_to_8(d, s) |
#define | fts_read_doc_id(s) mach_read_from_8(s) |
#define | fts_bind_doc_id(i, n, v) pars_info_bind_int8_literal(i, n, v) |
#define | FTS_NL 0 |
#define | FTS_BOOL 1 |
#define | FTS_SORTED 2 |
#define | FTS_EXPAND 4 |
#define | FTS_PROXIMITY 8 |
#define | FTS_PHRASE 16 |
#define | FTS_OPT_RANKING 32 |
#define | FTS_INDEX_TABLE_IND_NAME "FTS_INDEX_TABLE_IND" |
#define | FTS_OPTIMIZE_THRESHOLD 10000000 |
#define | FTS_DOC_ID_MAX_STEP 10000 |
#define | FTS_INIT_FTS_TABLE(fts_table, m_suffix, m_type, m_table) |
#define | FTS_INIT_INDEX_TABLE(fts_table, m_suffix, m_type, m_index) |
#define | STOPWORD_NOT_INIT 0x1 |
#define | STOPWORD_OFF 0x2 |
#define | STOPWORD_FROM_DEFAULT 0x4 |
#define | STOPWORD_USER_TABLE 0x8 |
#define | FTS_MAX_WORD_LEN HA_FT_MAXBYTELEN |
#define | FTS_MAX_WORD_LEN_IN_CHAR HA_FT_MAXCHARLEN |
#define | fts_que_graph_free(graph) |
Typedefs | |
typedef ib_uint64_t | doc_id_t |
typedef float | fts_rank_t |
typedef unsigned short | ib_uc_t |
typedef enum fts_status | fts_status_t |
Enumerations | |
enum | fts_row_state { FTS_INSERT = 0, FTS_MODIFY, FTS_DELETE, FTS_NOTHING, FTS_INVALID } |
enum | fts_table_type_t { FTS_INDEX_TABLE, FTS_COMMON_TABLE } |
enum | fts_status { BG_THREAD_STOP = 1, BG_THREAD_READY = 2, ADD_THREAD_STARTED = 4, ADDED_TABLE_SYNCED = 8, TABLE_DICT_LOCKED = 16 } |
Variables | |
ulong | fts_sort_pll_degree |
ulong | fts_num_word_optimize |
char | fts_enable_diag_print |
const char * | fts_default_stopword [] |
ulong | fts_max_cache_size |
ulong | fts_max_total_cache_size |
ulong | fts_result_cache_limit |
ulong | fts_max_token_size |
ulong | fts_min_token_size |
bool | fts_need_sync |
char * | fts_internal_tbl_name |
UNIV_INTERN dberr_t | warn_unused_result |
#define fts_bind_doc_id | ( | i, | |
n, | |||
v | |||
) | pars_info_bind_int8_literal(i, n, v) |
#define FTS_DOC_ID_COL_NAME "FTS_DOC_ID" |
#define FTS_DOC_ID_INDEX_NAME "FTS_DOC_ID_INDEX" |
#define FTS_INIT_FTS_TABLE | ( | fts_table, | |
m_suffix, | |||
m_type, | |||
m_table | |||
) |
#define FTS_INIT_INDEX_TABLE | ( | fts_table, | |
m_suffix, | |||
m_type, | |||
m_index | |||
) |
#define FTS_MAX_WORD_LEN HA_FT_MAXBYTELEN |
#define FTS_MAX_WORD_LEN_IN_CHAR HA_FT_MAXCHARLEN |
#define FTS_NL 0 |
Defines for FTS query mode, they have the same values as
those defined in mysql file ft_global.h
#define FTS_NUM_FIELDS_SORT 3 |
#define FTS_OPTIMIZE_THRESHOLD 10000000 |
#define fts_que_graph_free | ( | graph | ) |
#define fts_read_doc_id | ( | s | ) | mach_read_from_8(s) |
#define fts_write_doc_id | ( | d, | |
s | |||
) | mach_write_to_8(d, s) |
#define MAX_DOC_ID_OPT_VAL 1073741824 |
#define STOPWORD_NOT_INIT 0x1 |
status bits for fts_stopword_t status field.
typedef float fts_rank_t |
typedef unsigned short ib_uc_t |
Since MySQL's character set support for Unicode is woefully inadequate
(it supports basic operations like isalpha etc. only for 8-bit characters), we have to implement our own. We use UTF-16 without surrogate processing as our in-memory format. This typedef is a single such character.
enum fts_row_state |
Type of a row during a transaction. FTS_NOTHING means the row can be
forgotten from the FTS system's POV, FTS_INVALID is an internal value used to mark invalid states.
NOTE: Do not change the order or value of these, fts_trx_row_get_new_state depends on them being exactly as they are.
enum fts_status |
BG_THREAD_STOP |
TRUE if the FTS background thread has finished reading the ADDED table, meaning more items can be added to the table. |
BG_THREAD_READY |
TRUE if the FTS background thread is ready |
ADD_THREAD_STARTED |
TRUE if the FTS add thread has started |
ADDED_TABLE_SYNCED |
TRUE if the ADDED table record is sync-ed after crash recovery |
TABLE_DICT_LOCKED |
Set if the table has dict_sys->mutex |
enum fts_table_type_t |
UNIV_INTERN void fts_add_doc_id_column | ( | dict_table_t * | table, |
mem_heap_t * | heap | ||
) |
Add the FTS document id hidden column.
table | in/out: Table with FTS index |
heap | in: temporary memory heap, or NULL |
UNIV_INTERN void fts_add_index | ( | dict_index_t * | index, |
dict_table_t * | table | ||
) |
Add a newly create index in FTS cache table
Add a newly create index into FTS cache
index | FTS index to be added |
table | table |
Definition at line 685 of file fts0fts.cc.
UNIV_INTERN void fts_cache_clear | ( | fts_cache_t * | cache, |
ibool | free_words | ||
) |
Clear cache. If the shutdown flag is TRUE then the cache can contain data that needs to be freed. For regular clear as part of normal working we assume the caller has freed all resources. in: TRUE if free in memory word cache.
Clear cache. If the shutdown flag is TRUE then the cache can contain data that needs to be freed. For regular clear as part of normal working we assume the caller has freed all resources.
cache | in: cache |
free_words | in: TRUE if free in memory word cache. |
Definition at line 1087 of file fts0fts.cc.
UNIV_INTERN fts_cache_t* fts_cache_create | ( | dict_table_t * | table | ) |
Create a FTS cache. table owns the FTS cache
Create a FTS cache.
table | in: table owns the FTS cache |
Definition at line 621 of file fts0fts.cc.
UNIV_INTERN void fts_cache_destroy | ( | fts_cache_t * | cache | ) |
Free the FTS cache. in: cache
Free the FTS cache.
cache | in: cache |
Definition at line 1212 of file fts0fts.cc.
UNIV_INTERN fts_index_cache_t* fts_cache_index_cache_create | ( | dict_table_t * | table, |
dict_index_t * | index | ||
) |
Create a FTS index cache.
Create an FTS index cache.
table | in: table with FTS index |
index | in: FTS index |
Definition at line 1000 of file fts0fts.cc.
UNIV_INTERN void fts_cache_init | ( | fts_cache_t * | cache | ) |
Initialize things in cache. in: cache
Initialize FTS cache.
cache | in: cache to initialize |
Definition at line 590 of file fts0fts.cc.
UNIV_INTERN ibool fts_check_cached_index | ( | dict_table_t * | table | ) |
Check indexes in the fts->indexes is also present in index cache and table->indexes list
Check indexes in the fts->indexes is also present in index cache and table->indexes list
table | in: Table where indexes are dropped |
Definition at line 801 of file fts0fts.cc.
The given transaction is about to be committed; do whatever is necessary from the FTS system's POV.
trx | in: transaction |
UNIV_INTERN fts_t* fts_create | ( | dict_table_t * | table | ) |
UNIV_INTERN dberr_t fts_create_common_tables | ( | trx_t * | trx, |
const dict_table_t * | table, | ||
const char * | name, | ||
bool | skip_doc_id_index | ||
) |
Creates the common ancillary tables needed for supporting an FTS index on the given table. row_mysql_lock_data_dictionary must have been called before this.
trx | in: transaction handle |
table | in: table with one FTS index |
name | in: table name |
skip_doc_id_index | in: Skip index on doc id |
UNIV_INTERN dberr_t fts_create_doc_id | ( | dict_table_t * | table, |
dtuple_t * | row, | ||
mem_heap_t * | heap | ||
) |
Create a new document id .
table | in: row is of this table. |
row | in/out: add doc id value to this row. This is the current row that is being inserted. |
heap | in: heap |
UNIV_INTERN dberr_t fts_create_index_tables | ( | trx_t * | trx, |
const dict_index_t * | index | ||
) |
Wrapper function of fts_create_index_tables_low(), create auxiliary tables for an FTS index
trx | in: transaction handle |
index | in: the FTS index instance |
UNIV_INTERN dberr_t fts_create_index_tables_low | ( | trx_t * | trx, |
const dict_index_t * | index, | ||
const char * | table_name, | ||
table_id_t | table_id | ||
) |
Creates the column specific ancillary tables needed for supporting an FTS index on the given table. row_mysql_lock_data_dictionary must have been called before this.
trx | in: transaction handle |
index | in: the FTS index instance |
table_name | in: the table name |
table_id | in: the table id |
UNIV_INTERN fts_doc_ids_t* fts_doc_ids_create | ( | void | ) |
Create a new fts_doc_ids_t.
UNIV_INTERN void fts_doc_ids_free | ( | fts_doc_ids_t * | doc_ids | ) |
Free a fts_doc_ids_t. in: doc_ids to free
UNIV_INTERN dberr_t fts_drop_index | ( | dict_table_t * | table, |
dict_index_t * | index, | ||
trx_t * | trx | ||
) |
Drop auxiliary tables related to an FTS index
table | in: Table where indexes are dropped |
index | in: Index to be dropped |
trx | in: Transaction for the drop |
Definition at line 837 of file fts0fts.cc.
UNIV_INTERN dberr_t fts_drop_index_split_tables | ( | trx_t * | trx, |
dict_index_t * | index | ||
) |
Since we do a horizontal split on the index table, we need to drop all the split tables.
trx | in: transaction |
index | in: fts instance |
UNIV_INTERN dberr_t fts_drop_index_tables | ( | trx_t * | trx, |
dict_index_t * | index | ||
) |
Drops index ancillary tables for a FTS index
trx | in: transaction |
index | in: Index to drop |
UNIV_INTERN void fts_drop_orphaned_tables | ( | void | ) |
Drop all orphaned FTS auxiliary tables, those that don't have a parent table or FTS index defined on them.
UNIV_INTERN dberr_t fts_drop_tables | ( | trx_t * | trx, |
dict_table_t * | table | ||
) |
Drops the ancillary tables needed for supporting an FTS index on the given table. row_mysql_lock_data_dictionary must have been called before this.
trx | in: transaction |
table | in: table has the FTS index |
UNIV_INTERN void fts_free | ( | dict_table_t * | table | ) |
Free the FTS resources. in/out: table with FTS indexes
UNIV_INTERN doc_id_t fts_get_doc_id_from_rec | ( | dict_table_t * | table, |
const rec_t * | rec, | ||
mem_heap_t * | heap | ||
) |
Extract the doc id from the FTS hidden column. in: heap
table | in: table |
rec | in: rec |
UNIV_INTERN doc_id_t fts_get_doc_id_from_row | ( | dict_table_t * | table, |
dtuple_t * | row | ||
) |
Extract the doc id from the FTS hidden column. in: row whose FTS doc id we want to extract.
table | in: table |
UNIV_INTERN ib_vector_t* fts_get_docs_create | ( | fts_cache_t * | cache | ) |
Create the vector of fts_get_doc_t instances.
UNIV_INTERN doc_id_t fts_get_max_doc_id | ( | dict_table_t * | table | ) |
Get maximum Doc ID in a table if index "FTS_DOC_ID_INDEX" exists
UNIV_INTERN dberr_t fts_get_next_doc_id | ( | const dict_table_t * | table, |
doc_id_t * | doc_id | ||
) |
Get the next available document id. This function creates a new transaction to generate the document id.
table | in: table |
doc_id | out: new document id |
UNIV_INTERN ulint fts_get_rows_count | ( | fts_table_t * | fts_table | ) |
Fetch COUNT(*) from specified table.
UNIV_INTERN CHARSET_INFO* fts_index_get_charset | ( | dict_index_t * | index | ) |
Create an FTS index cache. in: FTS index
Create an FTS index cache.
index | in: FTS index |
Definition at line 955 of file fts0fts.cc.
UNIV_INTERN doc_id_t fts_init_doc_id | ( | const dict_table_t * | table | ) |
Get the initial Doc ID by consulting the CONFIG table
UNIV_INTERN ibool fts_init_index | ( | dict_table_t * | table, |
ibool | has_cache_lock | ||
) |
This function brings FTS index in sync when FTS index is first used. There are documents that have not yet sync-ed to auxiliary tables from last server abnormally shutdown, we will need to bring such document into FTS cache before any further operations
table | in: Table with FTS |
UNIV_INTERN ibool fts_load_stopword | ( | const dict_table_t * | table, |
trx_t * | trx, | ||
const char * | global_stopword_table, | ||
const char * | session_stopword_table, | ||
ibool | stopword_is_on, | ||
ibool | reload | ||
) |
This function loads specified stopword into FTS cache
table | in: Table with FTS |
trx | in: Transaction |
global_stopword_table | in: Global stopword table name |
session_stopword_table | in: Session stopword table name |
stopword_is_on | in: Whether stopword option is turned on/off |
UNIV_INTERN void fts_optimize_end | ( | void | ) |
Inform optimize to clean up.
UNIV_INTERN void fts_optimize_init | ( | void | ) |
Startup the optimize thread and create the work queue.
UNIV_INTERN ibool fts_optimize_is_init | ( | void | ) |
Check whether the work queue is initialized.
UNIV_INTERN void fts_optimize_remove_table | ( | dict_table_t * | table | ) |
Remove the table from the OPTIMIZER's list. We do wait for acknowledgement from the consumer of the message. in: table to remove
UNIV_INTERN void fts_optimize_start_shutdown | ( | void | ) |
Signal the optimize thread to prepare for shutdown.
UNIV_INTERN dberr_t fts_optimize_table | ( | dict_table_t * | table | ) |
UNIV_INTERN void fts_que_graph_free_check_lock | ( | fts_table_t * | fts_table, |
const fts_index_cache_t * | index_cache, | ||
que_t * | graph | ||
) |
Free the query graph but check whether dict_sys->mutex is already held in: query graph
Free the query graph but check whether dict_sys->mutex is already held
fts_table | in: FTS table |
index_cache | in: FTS index cache |
graph | in: query graph |
Definition at line 918 of file fts0fts.cc.
UNIV_INTERN dberr_t fts_query | ( | trx_t * | trx, |
dict_index_t * | index, | ||
uint | flags, | ||
const byte * | query, | ||
ulint | query_len, | ||
fts_result_t ** | result | ||
) |
FTS Query entry point.
trx | in: transaction |
index | in: FTS index to search |
flags | in: FTS search mode |
query | in: FTS query |
query_len | in: FTS query string len in bytes |
result | out: query result, to be freed by the caller. |
UNIV_INTERN void fts_query_free_result | ( | fts_result_t * | result | ) |
FTS Query free result, returned by fts_query(). in: result instance to free.
UNIV_INTERN void fts_query_sort_result_on_rank | ( | fts_result_t * | result | ) |
FTS Query sort result, returned by fts_query() on fts_ranking_t::rank. out: result instance to sort.
dberr_t fts_rename_aux_tables | ( | dict_table_t * | table, |
const char * | new_name, | ||
trx_t * | trx | ||
) |
Rename auxiliary tables for all fts index for a table
table | in: user Table |
new_name | in: new table name |
UNIV_INTERN float fts_retrieve_ranking | ( | fts_result_t * | result, |
doc_id_t | doc_id | ||
) |
Retrieve the FTS Relevance Ranking result for doc with doc_id
result | in: FTS result structure |
UNIV_INTERN void fts_savepoint_laststmt_refresh | ( | trx_t * | trx | ) |
Refresh last statement savepoint.
trx | in: transaction |
UNIV_INTERN void fts_savepoint_release | ( | trx_t * | trx, |
const char * | name | ||
) |
Release the savepoint data identified by name. in: savepoint name
trx | in: transaction |
UNIV_INTERN void fts_savepoint_rollback | ( | trx_t * | trx, |
const char * | name | ||
) |
Rollback to and including savepoint indentified by name. in: savepoint name
trx | in: transaction |
UNIV_INTERN void fts_savepoint_rollback_last_stmt | ( | trx_t * | trx | ) |
Rollback to and including savepoint indentified by name. in: transaction
UNIV_INTERN void fts_savepoint_take | ( | trx_t * | trx, |
const char * | name | ||
) |
Take a FTS savepoint.
trx | in: transaction |
name | in: savepoint name |
UNIV_INTERN void fts_shutdown | ( | dict_table_t * | table, |
fts_t * | fts | ||
) |
Wait for FTS threads to shutdown. in: fts instance to shutdown
table | in: table with FTS indexes |
UNIV_INTERN void fts_start_shutdown | ( | dict_table_t * | table, |
fts_t * | fts | ||
) |
Signal FTS threads to initiate shutdown. in: fts instance to shutdown
table | in: table with FTS indexes |
UNIV_INTERN void fts_startup | ( | void | ) |
FTS initialize.
UNIV_INTERN void fts_sync_table | ( | dict_table_t * | table | ) |
Run SYNC on the table, i.e., write out data from the cache to the FTS auxiliary INDEX table and clear the cache at the end.
table | in: table |
UNIV_INTERN dberr_t fts_table_fetch_doc_ids | ( | trx_t * | trx, |
fts_table_t * | fts_table, | ||
fts_doc_ids_t * | doc_ids | ||
) |
Read the rows from the FTS index
trx | in: transaction |
fts_table | in: aux table |
UNIV_INTERN void fts_trx_add_op | ( | trx_t * | trx, |
dict_table_t * | table, | ||
doc_id_t | doc_id, | ||
fts_row_state | state, | ||
ib_vector_t * | fts_indexes | ||
) |
Notify the FTS system about an operation on an FTS-indexed table.
trx | in: InnoDB transaction |
table | in: table |
doc_id | in: doc id |
state | in: state of the row |
fts_indexes | in: FTS indexes affected (NULL=all) |
UNIV_INTERN void UNIV_INTERN void fts_trx_free | ( | fts_trx_t * | fts_trx | ) |
Free an FTS trx. in, own: FTS trx
UNIV_INTERN doc_id_t fts_update_doc_id | ( | dict_table_t * | table, |
upd_field_t * | ufield, | ||
doc_id_t * | next_doc_id | ||
) |
Update the query graph with a new document id.
table | in: table |
ufield | out: update node |
UNIV_INTERN void fts_update_next_doc_id | ( | trx_t * | trx, |
const dict_table_t * | table, | ||
const char * | table_name, | ||
doc_id_t | doc_id | ||
) |
Update the next and last Doc ID in the CONFIG table to be the input "doc_id" value (+ 1). We would do so after each FTS index build or table truncate
trx | in/out: transaction |
table | in: table |
table_name | in: table name, or NULL |
doc_id | in: DOC ID to set |
UNIV_INTERN CHARSET_INFO* fts_valid_stopword_table | ( | const char * | stopword_table_name | ) |
Check whether user supplied stopword table exists and is of the right format.
size_t innobase_fts_casedn_str | ( | CHARSET_INFO * | cs, |
char * | src, | ||
size_t | src_len, | ||
char * | dst, | ||
size_t | dst_len | ||
) |
Makes all characters in a string lower case. in: buffer size
Makes all characters in a string lower case.
cs | in: Character set |
src | in: string to put in lower case |
src_len | in: input string length |
dst | in: buffer for result string |
dst_len | in: buffer size |
Definition at line 5370 of file ha_innodb.cc.
int innobase_fts_text_cmp | ( | const void * | cs, |
const void * | p1, | ||
const void * | p2 | ||
) |
compare two character string according to their charset. in: node
compare two character string according to their charset.
cs | in: Character set |
p1 | in: key |
p2 | in: node |
Definition at line 5263 of file ha_innodb.cc.
int innobase_fts_text_cmp_prefix | ( | const void * | cs, |
const void * | p1, | ||
const void * | p2 | ||
) |
compare two character string according to their charset. in: node
compare two character string according to their charset.
cs | in: Character set |
p1 | in: prefix key |
p2 | in: value to compare |
Definition at line 5331 of file ha_innodb.cc.
ulint innobase_mysql_fts_get_token | ( | CHARSET_INFO * | cs, |
const byte * | start, | ||
const byte * | end, | ||
fts_string_t * | token, | ||
ulint * | offset | ||
) |
Get the next token from the given string and store it in *token. out: offset to token, measured as characters from 'start'
Get the next token from the given string and store it in *token. It is mostly copied from MyISAM's doc parsing function ft_simple_get_word()
cs | in: Character set |
start | in: start of text |
end | in: one character past end of text |
token | out: token's text |
offset | out: offset to token, measured as characters from 'start' |
Definition at line 5399 of file ha_innodb.cc.
const char* fts_default_stopword[] |
InnoDB default stopword list:
There are different versions of stopwords, the stop words listed below comes from "Google Stopword" list. Reference: http://meta.wikimedia.org/wiki/Stop_word_list/google_stop_word_list. The final version of InnoDB default stopword list is still pending for decision
Definition at line 107 of file fts0fts.cc.
char fts_enable_diag_print |
Variable specifying whether we do additional FTS diagnostic printout
in the log
Definition at line 235 of file fts0opt.cc.
char* fts_internal_tbl_name |
Variable specifying the table that has Fulltext index to display its
content through information schema table
variable to record innodb_fts_internal_tbl_name for information
schema table INNODB_FTS_INSERTED etc.
Definition at line 99 of file fts0fts.cc.
ulong fts_max_cache_size |
Variable specifying the maximum FTS cache size for each table
This is maximum FTS cache for each table and would be
a configurable variable
Definition at line 49 of file fts0fts.cc.
ulong fts_max_token_size |
Variable specifying the maximum FTS max token size
Definition at line 63 of file fts0fts.cc.
ulong fts_max_total_cache_size |
Variable specifying the total memory allocated for FTS cache
Definition at line 56 of file fts0fts.cc.
ulong fts_min_token_size |
Variable specifying the minimum FTS max token size
Definition at line 66 of file fts0fts.cc.
bool fts_need_sync |
Whether the total memory used for FTS cache is exhausted, and we will
need a sync to free some memory
Definition at line 53 of file fts0fts.cc.
ulong fts_num_word_optimize |
Variable specifying the number of word to optimize for each optimize table
call
The number of words to read and optimize in a single pass.
Definition at line 232 of file fts0opt.cc.
ulong fts_result_cache_limit |
Variable specifying the FTS result cache limit for each query
This is FTS result cache limit for each query and would be
a configurable variable
Definition at line 60 of file fts0fts.cc.
ulong fts_sort_pll_degree |
Variable specifying the FTS parallel sort degree
Parallel sort degree
Definition at line 49 of file row0ftsort.cc.