1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved. |
4 | |
5 | This program is free software; you can redistribute it and/or modify it under |
6 | the terms of the GNU General Public License as published by the Free Software |
7 | Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License along with |
14 | this program; if not, write to the Free Software Foundation, Inc., |
15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /******************************************************************//** |
20 | @file include/fts0priv.ic |
21 | Full text search internal header file |
22 | |
23 | Created 2011/11/12 Sunny Bains |
24 | ***********************************************************************/ |
25 | |
26 | /******************************************************************//** |
27 | Write the table id to the given buffer (including final NUL). Buffer must be |
28 | at least FTS_AUX_MIN_TABLE_ID_LENGTH bytes long. |
29 | @return number of bytes written */ |
30 | UNIV_INLINE |
31 | int |
32 | fts_write_object_id( |
33 | /*================*/ |
34 | ib_id_t id, /* in: a table/index id */ |
35 | char* str, /* in: buffer to write the id to */ |
36 | bool hex_format MY_ATTRIBUTE((unused))) |
37 | /* in: true for fixed hex format, |
38 | false for old ambiguous format */ |
39 | { |
40 | |
41 | #ifdef _WIN32 |
42 | |
43 | DBUG_EXECUTE_IF("innodb_test_wrong_non_windows_fts_aux_table_name" , |
44 | return(sprintf(str, UINT64PFx, id));); |
45 | |
46 | /* Use this to construct old(5.6.14 and 5.7.3) windows |
47 | ambiguous aux table names */ |
48 | DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name" , |
49 | return(sprintf(str, "%016llu" , (ulonglong) id));); |
50 | |
51 | #else /* _WIN32 */ |
52 | |
53 | /* Use this to construct old(5.6.14 and 5.7.3) windows |
54 | ambiguous aux table names */ |
55 | DBUG_EXECUTE_IF("innodb_test_wrong_windows_fts_aux_table_name" , |
56 | return(sprintf(str, "%016llu" , (ulonglong) id));); |
57 | |
58 | DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name" , |
59 | return(sprintf(str, "%016llx" , (ulonglong) id));); |
60 | |
61 | #endif /* _WIN32 */ |
62 | |
63 | /* As above, but this is only for those tables failing to rename. */ |
64 | if (!hex_format) { |
65 | return(sprintf(str, "%016llu" , (ulonglong) id)); |
66 | } |
67 | |
68 | return(sprintf(str, "%016llx" , (ulonglong) id)); |
69 | } |
70 | |
71 | /******************************************************************//** |
72 | Read the table id from the string generated by fts_write_object_id(). |
73 | @return TRUE if parse successful */ |
74 | UNIV_INLINE |
75 | ibool |
76 | fts_read_object_id( |
77 | /*===============*/ |
78 | ib_id_t* id, /* out: an id */ |
79 | const char* str) /* in: buffer to read from */ |
80 | { |
81 | /* NOTE: this func doesn't care about whether current table |
82 | is set with HEX_NAME, the user of the id read here will check |
83 | if the id is HEX or DEC and do the right thing with it. */ |
84 | return(sscanf(str, UINT64PFx, id) == 1); |
85 | } |
86 | |
87 | /******************************************************************//** |
88 | Compare two fts_trx_table_t instances. |
89 | @return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */ |
90 | UNIV_INLINE |
91 | int |
92 | fts_trx_table_cmp( |
93 | /*==============*/ |
94 | const void* p1, /*!< in: id1 */ |
95 | const void* p2) /*!< in: id2 */ |
96 | { |
97 | const dict_table_t* table1 |
98 | = (*static_cast<const fts_trx_table_t* const*>(p1))->table; |
99 | |
100 | const dict_table_t* table2 |
101 | = (*static_cast<const fts_trx_table_t* const*>(p2))->table; |
102 | |
103 | return((table1->id > table2->id) |
104 | ? 1 |
105 | : (table1->id == table2->id) |
106 | ? 0 |
107 | : -1); |
108 | } |
109 | |
110 | /******************************************************************//** |
111 | Compare a table id with a fts_trx_table_t table id. |
112 | @return < 0 if n1 < n2, 0 if n1 == n2,> 0 if n1 > n2 */ |
113 | UNIV_INLINE |
114 | int |
115 | fts_trx_table_id_cmp( |
116 | /*=================*/ |
117 | const void* p1, /*!< in: id1 */ |
118 | const void* p2) /*!< in: id2 */ |
119 | { |
120 | const uintmax_t* table_id = static_cast<const uintmax_t*>(p1); |
121 | const dict_table_t* table2 |
122 | = (*static_cast<const fts_trx_table_t* const*>(p2))->table; |
123 | |
124 | return((*table_id > table2->id) |
125 | ? 1 |
126 | : (*table_id == table2->id) |
127 | ? 0 |
128 | : -1); |
129 | } |
130 | |