1 | /* Copyright (C) 2012-2017 Kentoku Shiba |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
15 | |
16 | #define MYSQL_SERVER 1 |
17 | #include <my_global.h> |
18 | #include "mysql_version.h" |
19 | #include "spd_environ.h" |
20 | #if MYSQL_VERSION_ID < 50500 |
21 | #include "mysql_priv.h" |
22 | #include <mysql/plugin.h> |
23 | #else |
24 | #include "sql_priv.h" |
25 | #include "probes_mysql.h" |
26 | #include "sql_analyse.h" |
27 | #endif |
28 | |
29 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
30 | #include "spd_err.h" |
31 | #include "spd_param.h" |
32 | #include "spd_db_include.h" |
33 | #include "spd_include.h" |
34 | #include "spd_db_handlersocket.h" |
35 | #include "ha_spider.h" |
36 | #include "spd_db_conn.h" |
37 | #include "spd_trx.h" |
38 | #include "spd_conn.h" |
39 | #include "spd_malloc.h" |
40 | |
41 | extern handlerton *spider_hton_ptr; |
42 | extern HASH spider_open_connections; |
43 | extern HASH spider_ipport_conns; |
44 | extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; |
45 | extern const char spider_dig_upper[]; |
46 | |
47 | #define SPIDER_SQL_INTERVAL_STR " + interval " |
48 | #define SPIDER_SQL_INTERVAL_LEN (sizeof(SPIDER_SQL_INTERVAL_STR) - 1) |
49 | #define SPIDER_SQL_NEGINTERVAL_STR " - interval " |
50 | #define SPIDER_SQL_NEGINTERVAL_LEN (sizeof(SPIDER_SQL_NEGINTERVAL_STR) - 1) |
51 | |
52 | #define SPIDER_SQL_NAME_QUOTE_STR "" |
53 | #define SPIDER_SQL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_NAME_QUOTE_STR) - 1) |
54 | static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; |
55 | |
56 | #define SPIDER_SQL_TYPE_FULL_HS (SPIDER_SQL_TYPE_SELECT_HS | \ |
57 | SPIDER_SQL_TYPE_INSERT_HS | SPIDER_SQL_TYPE_UPDATE_HS | \ |
58 | SPIDER_SQL_TYPE_DELETE_HS | SPIDER_SQL_TYPE_OTHER_HS) |
59 | |
60 | static uchar SPIDER_SQL_LINESTRING_HEAD_STR[] = |
61 | {0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00}; |
62 | #define SPIDER_SQL_LINESTRING_HEAD_LEN sizeof(SPIDER_SQL_LINESTRING_HEAD_STR) |
63 | |
64 | static const char *spider_db_timefunc_interval_str[] = |
65 | { |
66 | " year" , " quarter" , " month" , " week" , " day" , |
67 | " hour" , " minute" , " second" , " microsecond" , |
68 | " year_month" , " day_hour" , " day_minute" , |
69 | " day_second" , " hour_minute" , " hour_second" , |
70 | " minute_second" , " day_microsecond" , " hour_microsecond" , |
71 | " minute_microsecond" , " second_microsecond" |
72 | }; |
73 | |
74 | static SPIDER_HS_STRING_REF spider_null_string_ref = SPIDER_HS_STRING_REF(); |
75 | |
76 | int spider_handlersocket_init() |
77 | { |
78 | DBUG_ENTER("spider_handlersocket_init" ); |
79 | DBUG_RETURN(0); |
80 | } |
81 | |
82 | int spider_handlersocket_deinit() |
83 | { |
84 | DBUG_ENTER("spider_handlersocket_deinit" ); |
85 | DBUG_RETURN(0); |
86 | } |
87 | |
88 | spider_db_share *spider_handlersocket_create_share( |
89 | SPIDER_SHARE *share |
90 | ) { |
91 | DBUG_ENTER("spider_handlersocket_create_share" ); |
92 | DBUG_RETURN(new spider_handlersocket_share(share)); |
93 | } |
94 | |
95 | spider_db_handler *spider_handlersocket_create_handler( |
96 | ha_spider *spider, |
97 | spider_db_share *db_share |
98 | ) { |
99 | DBUG_ENTER("spider_handlersocket_create_handler" ); |
100 | DBUG_RETURN(new spider_handlersocket_handler(spider, |
101 | (spider_handlersocket_share *) db_share)); |
102 | } |
103 | |
104 | SPIDER_DB_CONN *spider_handlersocket_create_conn( |
105 | SPIDER_CONN *conn |
106 | ) { |
107 | DBUG_ENTER("spider_handlersocket_create_conn" ); |
108 | DBUG_RETURN(new spider_db_handlersocket(conn)); |
109 | } |
110 | |
111 | bool spider_handlersocket_support_direct_join( |
112 | ) { |
113 | DBUG_ENTER("spider_handlersocket_support_direct_join" ); |
114 | DBUG_RETURN(FALSE); |
115 | } |
116 | |
117 | spider_db_handlersocket_util spider_db_handlersocket_utility; |
118 | |
119 | SPIDER_DBTON spider_dbton_handlersocket = { |
120 | 0, |
121 | SPIDER_DB_WRAPPER_MYSQL, |
122 | SPIDER_DB_ACCESS_TYPE_NOSQL, |
123 | spider_handlersocket_init, |
124 | spider_handlersocket_deinit, |
125 | spider_handlersocket_create_share, |
126 | spider_handlersocket_create_handler, |
127 | NULL, |
128 | spider_handlersocket_create_conn, |
129 | spider_handlersocket_support_direct_join, |
130 | &spider_db_handlersocket_utility |
131 | }; |
132 | |
133 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
134 | spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer() |
135 | { |
136 | DBUG_ENTER("spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer" ); |
137 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
138 | DBUG_VOID_RETURN; |
139 | } |
140 | |
141 | spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer() |
142 | { |
143 | DBUG_ENTER("spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer" ); |
144 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
145 | DBUG_VOID_RETURN; |
146 | } |
147 | |
148 | int spider_db_hs_string_ref_buffer::init() |
149 | { |
150 | DBUG_ENTER("spider_db_hs_string_ref_buffer::init" ); |
151 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
152 | DBUG_RETURN(0); |
153 | } |
154 | |
155 | void spider_db_hs_string_ref_buffer::clear() |
156 | { |
157 | DBUG_ENTER("spider_db_hs_string_ref_buffer::clear" ); |
158 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
159 | hs_conds.clear(); |
160 | DBUG_VOID_RETURN; |
161 | } |
162 | |
163 | int spider_db_hs_string_ref_buffer::push_back( |
164 | SPIDER_HS_STRING_REF &cond |
165 | ) { |
166 | DBUG_ENTER("spider_db_hs_string_ref_buffer::push_back" ); |
167 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
168 | hs_conds.push_back(cond); |
169 | DBUG_RETURN(0); |
170 | } |
171 | |
172 | SPIDER_HS_STRING_REF *spider_db_hs_string_ref_buffer::ptr() |
173 | { |
174 | DBUG_ENTER("spider_db_hs_string_ref_buffer::ptr" ); |
175 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
176 | DBUG_RETURN(&hs_conds[0]); |
177 | } |
178 | |
179 | uint spider_db_hs_string_ref_buffer::size() |
180 | { |
181 | DBUG_ENTER("spider_db_hs_string_ref_buffer::size" ); |
182 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
183 | DBUG_RETURN((uint) hs_conds.size()); |
184 | } |
185 | #else |
186 | spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer() : hs_da_init(FALSE) |
187 | { |
188 | DBUG_ENTER("spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer" ); |
189 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
190 | DBUG_VOID_RETURN; |
191 | } |
192 | |
193 | spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer() |
194 | { |
195 | DBUG_ENTER("spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer" ); |
196 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
197 | if (hs_da_init) |
198 | { |
199 | spider_free_mem_calc(spider_current_trx, |
200 | hs_conds_id, hs_conds.max_element * hs_conds.size_of_element); |
201 | delete_dynamic(&hs_conds); |
202 | } |
203 | DBUG_VOID_RETURN; |
204 | } |
205 | |
206 | int spider_db_hs_string_ref_buffer::init() |
207 | { |
208 | DBUG_ENTER("spider_db_hs_string_ref_buffer::init" ); |
209 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
210 | if (!hs_da_init) |
211 | { |
212 | SPD_INIT_DYNAMIC_ARRAY2(&hs_conds, sizeof(SPIDER_HS_STRING_REF), |
213 | NULL, 16, 16, MYF(MY_WME)); |
214 | spider_alloc_calc_mem_init(hs_conds, 159); |
215 | spider_alloc_calc_mem(spider_current_trx, |
216 | hs_conds, hs_conds.max_element * hs_conds.size_of_element); |
217 | hs_da_init = TRUE; |
218 | } |
219 | DBUG_RETURN(0); |
220 | } |
221 | |
222 | void spider_db_hs_string_ref_buffer::clear() |
223 | { |
224 | DBUG_ENTER("spider_db_hs_string_ref_buffer::clear" ); |
225 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
226 | hs_conds.elements = 0; |
227 | DBUG_VOID_RETURN; |
228 | } |
229 | |
230 | int spider_db_hs_string_ref_buffer::push_back( |
231 | SPIDER_HS_STRING_REF &cond |
232 | ) { |
233 | uint old_elements = hs_conds.max_element; |
234 | DBUG_ENTER("spider_db_hs_string_ref_buffer::push_back" ); |
235 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
236 | if (insert_dynamic(&hs_conds, (uchar *) &cond)) |
237 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
238 | if (hs_conds.max_element > old_elements) |
239 | { |
240 | spider_alloc_calc_mem(spider_current_trx, |
241 | hs_conds, |
242 | (hs_conds.max_element - old_elements) * hs_conds.size_of_element); |
243 | } |
244 | DBUG_RETURN(0); |
245 | } |
246 | |
247 | SPIDER_HS_STRING_REF *spider_db_hs_string_ref_buffer::ptr() |
248 | { |
249 | DBUG_ENTER("spider_db_hs_string_ref_buffer::ptr" ); |
250 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
251 | DBUG_RETURN((SPIDER_HS_STRING_REF *) hs_conds.buffer); |
252 | } |
253 | |
254 | uint spider_db_hs_string_ref_buffer::size() |
255 | { |
256 | DBUG_ENTER("spider_db_hs_string_ref_buffer::size" ); |
257 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
258 | DBUG_RETURN(hs_conds.elements); |
259 | } |
260 | #endif |
261 | |
262 | spider_db_hs_str_buffer::spider_db_hs_str_buffer() : hs_da_init(FALSE) |
263 | { |
264 | DBUG_ENTER("spider_db_hs_str_buffer::spider_db_hs_str_buffer" ); |
265 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
266 | DBUG_VOID_RETURN; |
267 | } |
268 | |
269 | spider_db_hs_str_buffer::~spider_db_hs_str_buffer() |
270 | { |
271 | DBUG_ENTER("spider_db_hs_str_buffer::~spider_db_hs_str_buffer" ); |
272 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
273 | if (hs_da_init) |
274 | { |
275 | spider_free_mem_calc(spider_current_trx, |
276 | hs_conds_id, hs_conds.max_element * hs_conds.size_of_element); |
277 | delete_dynamic(&hs_conds); |
278 | } |
279 | DBUG_VOID_RETURN; |
280 | } |
281 | |
282 | int spider_db_hs_str_buffer::init() |
283 | { |
284 | DBUG_ENTER("spider_db_hs_str_buffer::init" ); |
285 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
286 | if (!hs_da_init) |
287 | { |
288 | SPD_INIT_DYNAMIC_ARRAY2(&hs_conds, sizeof(spider_string *), |
289 | NULL, 16, 16, MYF(MY_WME)); |
290 | spider_alloc_calc_mem_init(hs_conds, 160); |
291 | spider_alloc_calc_mem(spider_current_trx, |
292 | hs_conds, hs_conds.max_element * hs_conds.size_of_element); |
293 | hs_da_init = TRUE; |
294 | } |
295 | DBUG_RETURN(0); |
296 | } |
297 | |
298 | void spider_db_hs_str_buffer::clear() |
299 | { |
300 | uint i; |
301 | spider_string *element; |
302 | DBUG_ENTER("spider_db_hs_str_buffer::clear" ); |
303 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
304 | for (i = 0; i < hs_conds.elements; i++) |
305 | { |
306 | get_dynamic(&hs_conds, (uchar *) &element, i); |
307 | element->free(); |
308 | spider_free(spider_current_trx, element, MYF(0)); |
309 | } |
310 | hs_conds.elements = 0; |
311 | DBUG_VOID_RETURN; |
312 | } |
313 | |
314 | spider_string *spider_db_hs_str_buffer::add( |
315 | uint *strs_pos, |
316 | const char *str, |
317 | uint str_len |
318 | ) { |
319 | spider_string *element; |
320 | DBUG_ENTER("spider_db_hs_str_buffer::add" ); |
321 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
322 | if (hs_conds.elements <= *strs_pos + 1) |
323 | { |
324 | if (!(element = (spider_string *) spider_malloc(spider_current_trx, 8, |
325 | sizeof(spider_string), MYF(MY_WME | MY_ZEROFILL)))) |
326 | DBUG_RETURN(NULL); |
327 | element->init_calc_mem(98); |
328 | element->set_charset(&my_charset_bin); |
329 | if ((element->reserve(str_len + 1))) |
330 | { |
331 | spider_free(spider_current_trx, element, MYF(0)); |
332 | DBUG_RETURN(NULL); |
333 | } |
334 | element->q_append(str, str_len); |
335 | uint old_elements = hs_conds.max_element; |
336 | if (insert_dynamic(&hs_conds, (uchar *) &element)) |
337 | { |
338 | element->free(); |
339 | spider_free(spider_current_trx, element, MYF(0)); |
340 | DBUG_RETURN(NULL); |
341 | } |
342 | if (hs_conds.max_element > old_elements) |
343 | { |
344 | spider_alloc_calc_mem(spider_current_trx, |
345 | hs_conds, |
346 | (hs_conds.max_element - old_elements) * |
347 | hs_conds.size_of_element); |
348 | } |
349 | } else { |
350 | element = ((spider_string **) hs_conds.buffer)[*strs_pos]; |
351 | element->length(0); |
352 | if ((element->reserve(str_len + 1))) |
353 | DBUG_RETURN(NULL); |
354 | element->q_append(str, str_len); |
355 | } |
356 | (*strs_pos)++; |
357 | DBUG_RETURN(element); |
358 | } |
359 | |
360 | spider_db_handlersocket_row::spider_db_handlersocket_row() : |
361 | spider_db_row(spider_dbton_handlersocket.dbton_id), |
362 | hs_row(NULL), field_count(0), cloned(FALSE) |
363 | { |
364 | DBUG_ENTER("spider_db_handlersocket_row::spider_db_handlersocket_row" ); |
365 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
366 | DBUG_VOID_RETURN; |
367 | } |
368 | |
369 | spider_db_handlersocket_row::~spider_db_handlersocket_row() |
370 | { |
371 | DBUG_ENTER("spider_db_handlersocket_row::~spider_db_handlersocket_row" ); |
372 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
373 | if (cloned) |
374 | { |
375 | spider_free(spider_current_trx, hs_row_first, MYF(0)); |
376 | } |
377 | DBUG_VOID_RETURN; |
378 | } |
379 | |
380 | int spider_db_handlersocket_row::store_to_field( |
381 | Field *field, |
382 | CHARSET_INFO *access_charset |
383 | ) { |
384 | DBUG_ENTER("spider_db_handlersocket_row::store_to_field" ); |
385 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
386 | if (!hs_row->begin()) |
387 | { |
388 | DBUG_PRINT("info" , ("spider field is null" )); |
389 | field->set_null(); |
390 | field->reset(); |
391 | } else { |
392 | #ifndef DBUG_OFF |
393 | char buf[MAX_FIELD_WIDTH]; |
394 | spider_string tmp_str(buf, MAX_FIELD_WIDTH, field->charset()); |
395 | tmp_str.init_calc_mem(119); |
396 | tmp_str.length(0); |
397 | tmp_str.append(hs_row->begin(), hs_row->size(), &my_charset_bin); |
398 | DBUG_PRINT("info" , ("spider val=%s" , tmp_str.c_ptr_safe())); |
399 | #endif |
400 | field->set_notnull(); |
401 | if (field->flags & BLOB_FLAG) |
402 | { |
403 | DBUG_PRINT("info" , ("spider blob field" )); |
404 | ((Field_blob *)field)->set_ptr( |
405 | hs_row->size(), (uchar *) hs_row->begin()); |
406 | } else |
407 | field->store(hs_row->begin(), hs_row->size(), &my_charset_bin); |
408 | } |
409 | DBUG_RETURN(0); |
410 | } |
411 | |
412 | int spider_db_handlersocket_row::append_to_str( |
413 | spider_string *str |
414 | ) { |
415 | DBUG_ENTER("spider_db_handlersocket_row::append_to_str" ); |
416 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
417 | if (str->reserve(hs_row->size())) |
418 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
419 | str->q_append(hs_row->begin(), hs_row->size()); |
420 | DBUG_RETURN(0); |
421 | } |
422 | |
423 | int spider_db_handlersocket_row::append_escaped_to_str( |
424 | spider_string *str, |
425 | uint dbton_id |
426 | ) { |
427 | DBUG_ENTER("spider_db_handlersocket_row::append_escaped_to_str" ); |
428 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
429 | spider_string tmp_str(hs_row->begin(), hs_row->size() + 1, &my_charset_bin); |
430 | tmp_str.init_calc_mem(172); |
431 | tmp_str.length(hs_row->size()); |
432 | if (str->reserve(hs_row->size() * 2 + 2)) |
433 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
434 | spider_dbton[dbton_id].db_util->append_escaped_util(str, tmp_str.get_str()); |
435 | str->mem_calc(); |
436 | DBUG_RETURN(0); |
437 | } |
438 | |
439 | void spider_db_handlersocket_row::first() |
440 | { |
441 | DBUG_ENTER("spider_db_handlersocket_row::first" ); |
442 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
443 | hs_row = hs_row_first; |
444 | DBUG_VOID_RETURN; |
445 | } |
446 | |
447 | void spider_db_handlersocket_row::next() |
448 | { |
449 | DBUG_ENTER("spider_db_handlersocket_row::next" ); |
450 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
451 | hs_row++; |
452 | DBUG_VOID_RETURN; |
453 | } |
454 | |
455 | bool spider_db_handlersocket_row::is_null() |
456 | { |
457 | DBUG_ENTER("spider_db_handlersocket_row::is_null" ); |
458 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
459 | DBUG_RETURN(!hs_row->begin()); |
460 | } |
461 | |
462 | int spider_db_handlersocket_row::val_int() |
463 | { |
464 | DBUG_ENTER("spider_db_handlersocket_row::val_int" ); |
465 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
466 | DBUG_RETURN(atoi(hs_row->begin())); |
467 | } |
468 | |
469 | double spider_db_handlersocket_row::val_real() |
470 | { |
471 | DBUG_ENTER("spider_db_handlersocket_row::val_real" ); |
472 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
473 | DBUG_RETURN(hs_row->begin() ? my_atof(hs_row->begin()) : 0.0); |
474 | } |
475 | |
476 | my_decimal *spider_db_handlersocket_row::val_decimal( |
477 | my_decimal *decimal_value, |
478 | CHARSET_INFO *access_charset |
479 | ) { |
480 | DBUG_ENTER("spider_db_handlersocket_row::val_decimal" ); |
481 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
482 | if (!hs_row->begin()) |
483 | DBUG_RETURN(NULL); |
484 | |
485 | #ifdef SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE |
486 | decimal_operation_results(str2my_decimal(0, hs_row->begin(), hs_row->size(), |
487 | access_charset, decimal_value), "" , "" ); |
488 | #else |
489 | decimal_operation_results(str2my_decimal(0, hs_row->begin(), hs_row->size(), |
490 | access_charset, decimal_value)); |
491 | #endif |
492 | |
493 | DBUG_RETURN(decimal_value); |
494 | } |
495 | |
496 | SPIDER_DB_ROW *spider_db_handlersocket_row::clone() |
497 | { |
498 | spider_db_handlersocket_row *clone_row; |
499 | char *tmp_char; |
500 | uint row_size, i; |
501 | DBUG_ENTER("spider_db_handlersocket_row::clone" ); |
502 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
503 | if (!(clone_row = new spider_db_handlersocket_row())) |
504 | { |
505 | DBUG_RETURN(NULL); |
506 | } |
507 | row_size = 0; |
508 | for (i = 0; i < field_count; i++) |
509 | { |
510 | row_size += hs_row_first[i].size(); |
511 | } |
512 | if (!spider_bulk_malloc(spider_current_trx, 169, MYF(MY_WME), |
513 | &clone_row->hs_row, sizeof(SPIDER_HS_STRING_REF) * field_count, |
514 | &tmp_char, row_size, |
515 | NullS) |
516 | ) { |
517 | delete clone_row; |
518 | DBUG_RETURN(NULL); |
519 | } |
520 | for (i = 0; i < field_count; i++) |
521 | { |
522 | memcpy(tmp_char, hs_row_first[i].begin(), hs_row_first[i].size()); |
523 | clone_row->hs_row[i].set(tmp_char, hs_row_first[i].size()); |
524 | tmp_char += hs_row_first[i].size(); |
525 | } |
526 | clone_row->hs_row_first = clone_row->hs_row; |
527 | clone_row->cloned = TRUE;; |
528 | DBUG_RETURN(NULL); |
529 | } |
530 | |
531 | int spider_db_handlersocket_row::store_to_tmp_table( |
532 | TABLE *tmp_table, |
533 | spider_string *str |
534 | ) { |
535 | uint i; |
536 | SPIDER_HS_STRING_REF *tmp_hs_row = hs_row; |
537 | DBUG_ENTER("spider_db_handlersocket_row::store_to_tmp_table" ); |
538 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
539 | str->length(0); |
540 | for (i = 0; i < field_count; i++) |
541 | { |
542 | if (tmp_hs_row->begin()) |
543 | { |
544 | if (str->reserve(tmp_hs_row->size())) |
545 | { |
546 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
547 | } |
548 | str->q_append(tmp_hs_row->begin(), tmp_hs_row->size()); |
549 | } |
550 | tmp_hs_row++; |
551 | } |
552 | tmp_table->field[0]->set_notnull(); |
553 | tmp_table->field[0]->store( |
554 | (const char *) hs_row, |
555 | sizeof(SPIDER_HS_STRING_REF) * field_count, &my_charset_bin); |
556 | tmp_table->field[1]->set_notnull(); |
557 | tmp_table->field[1]->store( |
558 | str->ptr(), str->length(), &my_charset_bin); |
559 | tmp_table->field[2]->set_null(); |
560 | DBUG_RETURN(tmp_table->file->ha_write_row(tmp_table->record[0])); |
561 | } |
562 | |
563 | |
564 | spider_db_handlersocket_result_buffer::spider_db_handlersocket_result_buffer( |
565 | ) : spider_db_result_buffer() |
566 | { |
567 | DBUG_ENTER("spider_db_handlersocket_result_buffer::spider_db_handlersocket_result_buffer" ); |
568 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
569 | DBUG_VOID_RETURN; |
570 | } |
571 | |
572 | spider_db_handlersocket_result_buffer::~spider_db_handlersocket_result_buffer() |
573 | { |
574 | DBUG_ENTER( |
575 | "spider_db_handlersocket_result_buffer::~spider_db_handlersocket_result_buffer" ); |
576 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
577 | DBUG_VOID_RETURN; |
578 | } |
579 | |
580 | void spider_db_handlersocket_result_buffer::clear() |
581 | { |
582 | DBUG_ENTER("spider_db_handlersocket_result_buffer::clear" ); |
583 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
584 | hs_result.readbuf.clear(); |
585 | DBUG_VOID_RETURN; |
586 | } |
587 | |
588 | bool spider_db_handlersocket_result_buffer::check_size( |
589 | longlong size |
590 | ) { |
591 | DBUG_ENTER("spider_db_handlersocket_result_buffer::check_size" ); |
592 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
593 | if ((uint) hs_result.readbuf.real_size() > size) |
594 | { |
595 | hs_result.readbuf.real_free(); |
596 | DBUG_RETURN(TRUE); |
597 | } |
598 | DBUG_RETURN(FALSE); |
599 | } |
600 | |
601 | spider_db_handlersocket_result::spider_db_handlersocket_result( |
602 | SPIDER_DB_CONN *in_db_conn |
603 | ) : spider_db_result(in_db_conn, spider_dbton_handlersocket.dbton_id) |
604 | { |
605 | DBUG_ENTER("spider_db_handlersocket_result::spider_db_handlersocket_result" ); |
606 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
607 | DBUG_VOID_RETURN; |
608 | } |
609 | |
610 | spider_db_handlersocket_result::~spider_db_handlersocket_result() |
611 | { |
612 | DBUG_ENTER( |
613 | "spider_db_handlersocket_result::~spider_db_handlersocket_result" ); |
614 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
615 | DBUG_VOID_RETURN; |
616 | } |
617 | |
618 | bool spider_db_handlersocket_result::has_result() |
619 | { |
620 | DBUG_ENTER("spider_db_handlersocket_result::has_result" ); |
621 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
622 | DBUG_RETURN(((*hs_conn_p)->get_response_end_offset() > 0)); |
623 | } |
624 | |
625 | void spider_db_handlersocket_result::free_result() |
626 | { |
627 | DBUG_ENTER("spider_db_handlersocket_result::free_result" ); |
628 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
629 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
630 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
631 | (*hs_conn_p)->get_num_req_bufd())); |
632 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
633 | (*hs_conn_p)->get_num_req_sent())); |
634 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
635 | (*hs_conn_p)->get_num_req_rcvd())); |
636 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
637 | (*hs_conn_p)->get_response_end_offset())); |
638 | if ((*hs_conn_p)->get_response_end_offset() > 0) |
639 | { |
640 | (*hs_conn_p)->response_buf_remove(); |
641 | if ((*hs_conn_p)->get_error_code()) |
642 | { |
643 | DBUG_PRINT("info" ,("spider hs %d %s" , |
644 | (*hs_conn_p)->get_error_code(), |
645 | (*hs_conn_p)->get_error().ptr())); |
646 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
647 | } |
648 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
649 | (*hs_conn_p)->get_num_req_bufd())); |
650 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
651 | (*hs_conn_p)->get_num_req_sent())); |
652 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
653 | (*hs_conn_p)->get_num_req_rcvd())); |
654 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
655 | (*hs_conn_p)->get_response_end_offset())); |
656 | } |
657 | DBUG_VOID_RETURN; |
658 | } |
659 | |
660 | SPIDER_DB_ROW *spider_db_handlersocket_result::current_row() |
661 | { |
662 | DBUG_ENTER("spider_db_handlersocket_result::current_row" ); |
663 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
664 | DBUG_RETURN((SPIDER_DB_ROW *) row.clone()); |
665 | } |
666 | |
667 | SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row() |
668 | { |
669 | DBUG_ENTER("spider_db_handlersocket_result::fetch_row" ); |
670 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
671 | if (!(row.hs_row = (SPIDER_HS_STRING_REF *) |
672 | (*hs_conn_p)->get_next_row())) |
673 | { |
674 | store_error_num = HA_ERR_END_OF_FILE; |
675 | DBUG_RETURN(NULL); |
676 | } |
677 | row.field_count = field_count; |
678 | row.hs_row_first = row.hs_row; |
679 | DBUG_RETURN((SPIDER_DB_ROW *) &row); |
680 | } |
681 | |
682 | SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row_from_result_buffer( |
683 | spider_db_result_buffer *spider_res_buf |
684 | ) { |
685 | spider_db_handlersocket_result_buffer *hs_res_buf; |
686 | DBUG_ENTER("spider_db_handlersocket_result::fetch_row_from_result_buffer" ); |
687 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
688 | hs_res_buf = (spider_db_handlersocket_result_buffer *) spider_res_buf; |
689 | if (!(row.hs_row = (SPIDER_HS_STRING_REF *) |
690 | (*hs_conn_p)->get_next_row_from_result(hs_res_buf->hs_result))) |
691 | { |
692 | store_error_num = HA_ERR_END_OF_FILE; |
693 | DBUG_RETURN(NULL); |
694 | } |
695 | row.field_count = field_count; |
696 | row.hs_row_first = row.hs_row; |
697 | DBUG_RETURN((SPIDER_DB_ROW *) &row); |
698 | } |
699 | |
700 | SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row_from_tmp_table( |
701 | TABLE *tmp_table |
702 | ) { |
703 | uint i; |
704 | spider_string tmp_str1, tmp_str2; |
705 | const char *row_ptr; |
706 | SPIDER_HS_STRING_REF *tmp_hs_row; |
707 | uint field_count; |
708 | DBUG_ENTER("spider_db_handlersocket_result::fetch_row_from_tmp_table" ); |
709 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
710 | tmp_str1.init_calc_mem(171); |
711 | tmp_str2.init_calc_mem(173); |
712 | tmp_table->field[0]->val_str(tmp_str1.get_str()); |
713 | tmp_table->field[1]->val_str(tmp_str2.get_str()); |
714 | tmp_str1.mem_calc(); |
715 | tmp_str2.mem_calc(); |
716 | row_ptr = tmp_str2.ptr(); |
717 | tmp_hs_row = (SPIDER_HS_STRING_REF *) tmp_str1.ptr(); |
718 | field_count = tmp_str1.length() / sizeof(SPIDER_HS_STRING_REF); |
719 | row.hs_row = tmp_hs_row; |
720 | row.field_count = field_count; |
721 | row.hs_row_first = row.hs_row; |
722 | for (i = 0; i < field_count; i++) |
723 | { |
724 | if (tmp_hs_row->begin()) |
725 | { |
726 | uint length = tmp_hs_row->size(); |
727 | tmp_hs_row->set(row_ptr, length); |
728 | row_ptr += length; |
729 | } |
730 | tmp_hs_row++; |
731 | } |
732 | DBUG_RETURN((SPIDER_DB_ROW *) &row); |
733 | } |
734 | |
735 | int spider_db_handlersocket_result::fetch_table_status( |
736 | int mode, |
737 | ha_rows &records, |
738 | ulong &mean_rec_length, |
739 | ulonglong &data_file_length, |
740 | ulonglong &max_data_file_length, |
741 | ulonglong &index_file_length, |
742 | ulonglong &auto_increment_value, |
743 | time_t &create_time, |
744 | time_t &update_time, |
745 | time_t &check_time |
746 | ) { |
747 | DBUG_ENTER("spider_db_handlersocket_result::fetch_table_status" ); |
748 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
749 | DBUG_ASSERT(0); |
750 | DBUG_RETURN(0); |
751 | } |
752 | |
753 | int spider_db_handlersocket_result::fetch_table_records( |
754 | int mode, |
755 | ha_rows &records |
756 | ) { |
757 | DBUG_ENTER("spider_db_handlersocket_result::fetch_table_records" ); |
758 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
759 | DBUG_ASSERT(0); |
760 | DBUG_RETURN(0); |
761 | } |
762 | |
763 | int spider_db_handlersocket_result::fetch_table_cardinality( |
764 | int mode, |
765 | TABLE *table, |
766 | longlong *cardinality, |
767 | uchar *cardinality_upd, |
768 | int bitmap_size |
769 | ) { |
770 | DBUG_ENTER("spider_db_handlersocket_result::fetch_table_cardinality" ); |
771 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
772 | DBUG_ASSERT(0); |
773 | DBUG_RETURN(0); |
774 | } |
775 | |
776 | int spider_db_handlersocket_result::fetch_table_mon_status( |
777 | int &status |
778 | ) { |
779 | DBUG_ENTER("spider_db_handlersocket_result::fetch_table_mon_status" ); |
780 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
781 | DBUG_ASSERT(0); |
782 | DBUG_RETURN(0); |
783 | } |
784 | |
785 | longlong spider_db_handlersocket_result::num_rows() |
786 | { |
787 | DBUG_ENTER("spider_db_handlersocket_result::num_rows" ); |
788 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
789 | DBUG_RETURN((longlong) 0); |
790 | } |
791 | |
792 | uint spider_db_handlersocket_result::num_fields() |
793 | { |
794 | DBUG_ENTER("spider_db_handlersocket_result::num_fields" ); |
795 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
796 | DBUG_RETURN(field_count); |
797 | } |
798 | |
799 | void spider_db_handlersocket_result::move_to_pos( |
800 | longlong pos |
801 | ) { |
802 | DBUG_ENTER("spider_db_handlersocket_result::move_to_pos" ); |
803 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
804 | DBUG_ASSERT(0); |
805 | DBUG_VOID_RETURN; |
806 | } |
807 | |
808 | int spider_db_handlersocket_result::get_errno() |
809 | { |
810 | DBUG_ENTER("spider_db_handlersocket_result::get_errno" ); |
811 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
812 | DBUG_PRINT("info" ,("spider store_error_num=%d" , store_error_num)); |
813 | DBUG_RETURN(store_error_num); |
814 | } |
815 | |
816 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
817 | int spider_db_handlersocket_result::fetch_columns_for_discover_table_structure( |
818 | spider_string *str, |
819 | CHARSET_INFO *access_charset |
820 | ) { |
821 | DBUG_ENTER("spider_db_handlersocket_result::fetch_columns_for_discover_table_structure" ); |
822 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
823 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
824 | } |
825 | |
826 | int spider_db_handlersocket_result::fetch_index_for_discover_table_structure( |
827 | spider_string *str, |
828 | CHARSET_INFO *access_charset |
829 | ) { |
830 | DBUG_ENTER("spider_db_handlersocket_result::fetch_index_for_discover_table_structure" ); |
831 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
832 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
833 | } |
834 | |
835 | int spider_db_handlersocket_result::fetch_table_for_discover_table_structure( |
836 | spider_string *str, |
837 | SPIDER_SHARE *spider_share, |
838 | CHARSET_INFO *access_charset |
839 | ) { |
840 | DBUG_ENTER("spider_db_handlersocket_result::fetch_table_for_discover_table_structure" ); |
841 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
842 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
843 | } |
844 | #endif |
845 | |
846 | spider_db_handlersocket::spider_db_handlersocket( |
847 | SPIDER_CONN *conn |
848 | ) : spider_db_conn(conn), |
849 | handler_open_array_inited(FALSE), |
850 | request_key_req_first(NULL), |
851 | request_key_req_last(NULL), |
852 | request_key_snd_first(NULL), |
853 | request_key_snd_last(NULL), |
854 | request_key_reuse_first(NULL), |
855 | request_key_reuse_last(NULL) |
856 | { |
857 | DBUG_ENTER("spider_db_handlersocket::spider_db_handlersocket" ); |
858 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
859 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
860 | #else |
861 | hs_conn = NULL; |
862 | #endif |
863 | DBUG_VOID_RETURN; |
864 | } |
865 | |
866 | spider_db_handlersocket::~spider_db_handlersocket() |
867 | { |
868 | st_spider_db_request_key *tmp_request_key; |
869 | DBUG_ENTER("spider_db_handlersocket::~spider_db_handlersocket" ); |
870 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
871 | if (handler_open_array_inited) |
872 | { |
873 | reset_opened_handler(); |
874 | spider_free_mem_calc(spider_current_trx, |
875 | handler_open_array_id, |
876 | handler_open_array.max_element * |
877 | handler_open_array.size_of_element); |
878 | delete_dynamic(&handler_open_array); |
879 | } |
880 | while (request_key_req_first) |
881 | { |
882 | tmp_request_key = request_key_req_first->next; |
883 | spider_free(spider_current_trx, request_key_req_first, MYF(0)); |
884 | request_key_req_first = tmp_request_key; |
885 | } |
886 | while (request_key_snd_first) |
887 | { |
888 | tmp_request_key = request_key_snd_first->next; |
889 | spider_free(spider_current_trx, request_key_snd_first, MYF(0)); |
890 | request_key_snd_first = tmp_request_key; |
891 | } |
892 | while (request_key_reuse_first) |
893 | { |
894 | tmp_request_key = request_key_reuse_first->next; |
895 | spider_free(spider_current_trx, request_key_reuse_first, MYF(0)); |
896 | request_key_reuse_first = tmp_request_key; |
897 | } |
898 | DBUG_VOID_RETURN; |
899 | } |
900 | |
901 | int spider_db_handlersocket::init() |
902 | { |
903 | DBUG_ENTER("spider_db_handlersocket::init" ); |
904 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
905 | if ( |
906 | SPD_INIT_DYNAMIC_ARRAY2(&handler_open_array, |
907 | sizeof(SPIDER_LINK_FOR_HASH *), NULL, 16, 16, MYF(MY_WME)) |
908 | ) { |
909 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
910 | } |
911 | spider_alloc_calc_mem_init(handler_open_array, 79); |
912 | spider_alloc_calc_mem(spider_current_trx, |
913 | handler_open_array, |
914 | handler_open_array.max_element * |
915 | handler_open_array.size_of_element); |
916 | handler_open_array_inited = TRUE; |
917 | DBUG_RETURN(0); |
918 | } |
919 | |
920 | bool spider_db_handlersocket::is_connected() |
921 | { |
922 | DBUG_ENTER("spider_db_handlersocket::is_connected" ); |
923 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
924 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
925 | DBUG_RETURN(hs_conn.operator->()); |
926 | #else |
927 | DBUG_RETURN(hs_conn); |
928 | #endif |
929 | } |
930 | |
931 | void spider_db_handlersocket::bg_connect() |
932 | { |
933 | DBUG_ENTER("spider_db_handlersocket::bg_connect" ); |
934 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
935 | DBUG_VOID_RETURN; |
936 | } |
937 | |
938 | int spider_db_handlersocket::connect( |
939 | char *tgt_host, |
940 | char *tgt_username, |
941 | char *tgt_password, |
942 | long tgt_port, |
943 | char *tgt_socket, |
944 | char *server_name, |
945 | int connect_retry_count, |
946 | longlong connect_retry_interval |
947 | ) { |
948 | DBUG_ENTER("spider_db_handlersocket::connect" ); |
949 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
950 | SPIDER_HS_SOCKARGS sockargs; |
951 | sockargs.timeout = conn->connect_timeout; |
952 | sockargs.recv_timeout = conn->net_read_timeout; |
953 | sockargs.send_timeout = conn->net_write_timeout; |
954 | if (conn->hs_sock) |
955 | { |
956 | sockargs.family = AF_UNIX; |
957 | sockargs.set_unix_domain(conn->hs_sock); |
958 | } else { |
959 | char port_str[6]; |
960 | my_sprintf(port_str, (port_str, "%05ld" , conn->hs_port)); |
961 | if (sockargs.resolve(conn->tgt_host, port_str) != 0) |
962 | { |
963 | my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), |
964 | conn->tgt_host); |
965 | DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); |
966 | } |
967 | } |
968 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
969 | if (!(hs_conn.operator->())) |
970 | #else |
971 | if (!(hs_conn)) |
972 | #endif |
973 | { |
974 | hs_conn = SPIDER_HS_CONN_CREATE(sockargs); |
975 | } else { |
976 | hs_conn->reconnect(); |
977 | spider_db_hs_request_buf_reset(conn); |
978 | } |
979 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
980 | if (!(hs_conn.operator->())) |
981 | #else |
982 | if (!(hs_conn)) |
983 | #endif |
984 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
985 | while (hs_conn->get_error_code()) |
986 | { |
987 | THD *thd = current_thd; |
988 | if ( |
989 | !connect_retry_count || |
990 | (thd && thd->killed) |
991 | ) { |
992 | my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), |
993 | conn->tgt_host); |
994 | DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); |
995 | } |
996 | connect_retry_count--; |
997 | my_sleep((ulong) connect_retry_interval); |
998 | hs_conn->reconnect(); |
999 | } |
1000 | reset_request_key_req(); |
1001 | reset_request_key_snd(); |
1002 | DBUG_RETURN(0); |
1003 | } |
1004 | |
1005 | int spider_db_handlersocket::ping() |
1006 | { |
1007 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1008 | DBUG_ENTER("spider_db_handlersocket::ping" ); |
1009 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1010 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1011 | (*hs_conn_p)->get_num_req_bufd())); |
1012 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1013 | (*hs_conn_p)->get_num_req_sent())); |
1014 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1015 | (*hs_conn_p)->get_num_req_rcvd())); |
1016 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1017 | (*hs_conn_p)->get_response_end_offset())); |
1018 | if ((*hs_conn_p)->reconnect()) |
1019 | { |
1020 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1021 | (*hs_conn_p)->get_num_req_bufd())); |
1022 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1023 | (*hs_conn_p)->get_num_req_sent())); |
1024 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1025 | (*hs_conn_p)->get_num_req_rcvd())); |
1026 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1027 | (*hs_conn_p)->get_response_end_offset())); |
1028 | DBUG_RETURN(ER_SPIDER_HS_NUM); |
1029 | } |
1030 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1031 | (*hs_conn_p)->get_num_req_bufd())); |
1032 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1033 | (*hs_conn_p)->get_num_req_sent())); |
1034 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1035 | (*hs_conn_p)->get_num_req_rcvd())); |
1036 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1037 | (*hs_conn_p)->get_response_end_offset())); |
1038 | |
1039 | reset_request_key_req(); |
1040 | reset_request_key_snd(); |
1041 | conn->opened_handlers = 0; |
1042 | conn->db_conn->reset_opened_handler(); |
1043 | ++conn->connection_id; |
1044 | DBUG_RETURN(0); |
1045 | } |
1046 | |
1047 | void spider_db_handlersocket::bg_disconnect() |
1048 | { |
1049 | DBUG_ENTER("spider_db_handlersocket::bg_disconnect" ); |
1050 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1051 | DBUG_VOID_RETURN; |
1052 | } |
1053 | |
1054 | void spider_db_handlersocket::disconnect() |
1055 | { |
1056 | DBUG_ENTER("spider_db_handlersocket::disconnect" ); |
1057 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1058 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
1059 | if (hs_conn.operator->()) |
1060 | #else |
1061 | DBUG_PRINT("info" ,("spider hs_conn=%p" , hs_conn)); |
1062 | if (hs_conn) |
1063 | #endif |
1064 | { |
1065 | hs_conn->close(); |
1066 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
1067 | SPIDER_HS_CONN tmp_hs_conn; |
1068 | tmp_hs_conn = hs_conn; |
1069 | #else |
1070 | delete hs_conn; |
1071 | hs_conn = NULL; |
1072 | #endif |
1073 | } |
1074 | DBUG_VOID_RETURN; |
1075 | } |
1076 | |
1077 | int spider_db_handlersocket::set_net_timeout() |
1078 | { |
1079 | DBUG_ENTER("spider_db_handlersocket::set_net_timeout" ); |
1080 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1081 | DBUG_RETURN(hs_conn->set_timeout( |
1082 | conn->net_write_timeout, |
1083 | conn->net_read_timeout |
1084 | )); |
1085 | } |
1086 | |
1087 | int spider_db_handlersocket::exec_query( |
1088 | const char *query, |
1089 | uint length, |
1090 | int quick_mode |
1091 | ) { |
1092 | DBUG_ENTER("spider_db_handlersocket::query" ); |
1093 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1094 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1095 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
1096 | DBUG_PRINT("info" , ("spider hs_conn %p" , hs_conn.operator->())); |
1097 | #else |
1098 | DBUG_PRINT("info" , ("spider hs_conn %p" , hs_conn)); |
1099 | #endif |
1100 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1101 | (*hs_conn_p)->get_num_req_bufd())); |
1102 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1103 | (*hs_conn_p)->get_num_req_sent())); |
1104 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1105 | (*hs_conn_p)->get_num_req_rcvd())); |
1106 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1107 | (*hs_conn_p)->get_response_end_offset())); |
1108 | if (spider_param_general_log()) |
1109 | { |
1110 | const char *tgt_str = conn->hs_sock ? conn->hs_sock : conn->tgt_host; |
1111 | uint32 tgt_len = strlen(tgt_str); |
1112 | spider_string tmp_query_str((*hs_conn_p)->get_writebuf_size() + |
1113 | conn->tgt_wrapper_length + |
1114 | tgt_len + (SPIDER_SQL_SPACE_LEN * 2)); |
1115 | tmp_query_str.init_calc_mem(231); |
1116 | tmp_query_str.length(0); |
1117 | tmp_query_str.q_append(conn->tgt_wrapper, conn->tgt_wrapper_length); |
1118 | tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
1119 | tmp_query_str.q_append(tgt_str, tgt_len); |
1120 | tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
1121 | tmp_query_str.q_append((*hs_conn_p)->get_writebuf_begin(), |
1122 | (*hs_conn_p)->get_writebuf_size()); |
1123 | general_log_write(current_thd, COM_QUERY, tmp_query_str.ptr(), |
1124 | tmp_query_str.length()); |
1125 | } |
1126 | if ((*hs_conn_p)->request_send() < 0) |
1127 | { |
1128 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1129 | (*hs_conn_p)->get_num_req_bufd())); |
1130 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1131 | (*hs_conn_p)->get_num_req_sent())); |
1132 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1133 | (*hs_conn_p)->get_num_req_rcvd())); |
1134 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1135 | (*hs_conn_p)->get_response_end_offset())); |
1136 | DBUG_RETURN(ER_SPIDER_HS_NUM); |
1137 | } |
1138 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1139 | (*hs_conn_p)->get_num_req_bufd())); |
1140 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1141 | (*hs_conn_p)->get_num_req_sent())); |
1142 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1143 | (*hs_conn_p)->get_num_req_rcvd())); |
1144 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1145 | (*hs_conn_p)->get_response_end_offset())); |
1146 | move_request_key_to_snd(); |
1147 | DBUG_RETURN(0); |
1148 | } |
1149 | |
1150 | int spider_db_handlersocket::get_errno() |
1151 | { |
1152 | DBUG_ENTER("spider_db_handlersocket::get_errno" ); |
1153 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1154 | stored_error = hs_conn->get_error_code(); |
1155 | DBUG_PRINT("info" ,("spider stored_error=%d" , stored_error)); |
1156 | DBUG_RETURN(stored_error); |
1157 | } |
1158 | |
1159 | const char *spider_db_handlersocket::get_error() |
1160 | { |
1161 | const char *error_ptr; |
1162 | DBUG_ENTER("spider_db_handlersocket::get_error" ); |
1163 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1164 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
1165 | error_ptr = hs_conn->get_error().c_str(); |
1166 | #else |
1167 | error_ptr = hs_conn->get_error().c_ptr(); |
1168 | #endif |
1169 | DBUG_PRINT("info" ,("spider error=%s" , error_ptr)); |
1170 | DBUG_RETURN(error_ptr); |
1171 | } |
1172 | |
1173 | bool spider_db_handlersocket::is_server_gone_error( |
1174 | int error_num |
1175 | ) { |
1176 | bool server_gone; |
1177 | DBUG_ENTER("spider_db_handlersocket::is_server_gone_error" ); |
1178 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1179 | server_gone = (hs_conn->get_error_code() < 0); |
1180 | DBUG_PRINT("info" ,("spider server_gone=%s" , server_gone ? "TRUE" : "FALSE" )); |
1181 | DBUG_RETURN(server_gone); |
1182 | } |
1183 | |
1184 | bool spider_db_handlersocket::is_dup_entry_error( |
1185 | int error_num |
1186 | ) { |
1187 | bool dup_entry; |
1188 | DBUG_ENTER("spider_db_handlersocket::is_dup_entry_error" ); |
1189 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1190 | #ifndef HANDLERSOCKET_MYSQL_UTIL |
1191 | const char *c_str = hs_conn->get_error().c_str(); |
1192 | #else |
1193 | const char *c_str = hs_conn->get_error().c_ptr_safe(); |
1194 | #endif |
1195 | dup_entry = |
1196 | ( |
1197 | c_str[0] == '1' && |
1198 | c_str[1] == '2' && |
1199 | c_str[2] == '1' && |
1200 | c_str[3] == '\0' |
1201 | ); |
1202 | DBUG_PRINT("info" ,("spider dup_entry=%s" , dup_entry ? "TRUE" : "FALSE" )); |
1203 | DBUG_RETURN(dup_entry); |
1204 | } |
1205 | |
1206 | bool spider_db_handlersocket::is_xa_nota_error( |
1207 | int error_num |
1208 | ) { |
1209 | bool xa_nota; |
1210 | DBUG_ENTER("spider_db_handlersocket::is_xa_nota_error" ); |
1211 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1212 | DBUG_ASSERT(0); |
1213 | xa_nota = (stored_error == ER_XAER_NOTA); |
1214 | DBUG_PRINT("info" ,("spider xa_nota=%s" , xa_nota ? "TRUE" : "FALSE" )); |
1215 | DBUG_RETURN(xa_nota); |
1216 | } |
1217 | |
1218 | spider_db_result *spider_db_handlersocket::store_result( |
1219 | spider_db_result_buffer **spider_res_buf, |
1220 | st_spider_db_request_key *request_key, |
1221 | int *error_num |
1222 | ) { |
1223 | int internal_error; |
1224 | spider_db_handlersocket_result *result; |
1225 | spider_db_handlersocket_result_buffer *hs_res_buf; |
1226 | DBUG_ENTER("spider_db_handlersocket::store_result" ); |
1227 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1228 | if (*spider_res_buf) |
1229 | { |
1230 | hs_res_buf = (spider_db_handlersocket_result_buffer *) *spider_res_buf; |
1231 | } else { |
1232 | if (!(hs_res_buf = new spider_db_handlersocket_result_buffer())) |
1233 | { |
1234 | *error_num = HA_ERR_OUT_OF_MEM; |
1235 | DBUG_RETURN(NULL); |
1236 | } |
1237 | *spider_res_buf = (spider_db_result_buffer *) hs_res_buf; |
1238 | } |
1239 | hs_res_buf->clear(); |
1240 | if (!(result = new spider_db_handlersocket_result(this))) |
1241 | { |
1242 | *error_num = HA_ERR_OUT_OF_MEM; |
1243 | DBUG_RETURN(NULL); |
1244 | } |
1245 | *error_num = 0; |
1246 | result->hs_conn_p = &hs_conn; |
1247 | size_t num_fields; |
1248 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1249 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1250 | if (request_key) |
1251 | { |
1252 | int tmp_res, tmp_err = (*hs_conn_p)->get_error_code(); |
1253 | while ((tmp_res = check_request_key(request_key)) == 1) |
1254 | { |
1255 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1256 | (*hs_conn_p)->get_num_req_bufd())); |
1257 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1258 | (*hs_conn_p)->get_num_req_sent())); |
1259 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1260 | (*hs_conn_p)->get_num_req_rcvd())); |
1261 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1262 | (*hs_conn_p)->get_response_end_offset())); |
1263 | if ((internal_error = (*hs_conn_p)->response_recv(num_fields))) |
1264 | { |
1265 | if (!tmp_err && internal_error > 0) |
1266 | { |
1267 | (*hs_conn_p)->clear_error(); |
1268 | } else { |
1269 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1270 | #ifndef DBUG_OFF |
1271 | if ((*hs_conn_p)->get_response_end_offset() > 0 && |
1272 | (*hs_conn_p)->get_readbuf_begin()) |
1273 | { |
1274 | char tmp_buf[MAX_FIELD_WIDTH]; |
1275 | String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); |
1276 | tmp_str.length(0); |
1277 | tmp_str.append((*hs_conn_p)->get_readbuf_begin(), |
1278 | (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); |
1279 | DBUG_PRINT("info" ,("spider hs readbuf01 size=%zu str=%s" , |
1280 | (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); |
1281 | } |
1282 | #endif |
1283 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1284 | (*hs_conn_p)->get_num_req_bufd())); |
1285 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1286 | (*hs_conn_p)->get_num_req_sent())); |
1287 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1288 | (*hs_conn_p)->get_num_req_rcvd())); |
1289 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1290 | (*hs_conn_p)->get_response_end_offset())); |
1291 | if (internal_error > 0) |
1292 | { |
1293 | (*hs_conn_p)->response_buf_remove(); |
1294 | if ((*hs_conn_p)->get_error_code()) |
1295 | { |
1296 | DBUG_PRINT("info" ,("spider hs %d %s" , |
1297 | (*hs_conn_p)->get_error_code(), |
1298 | (*hs_conn_p)->get_error().ptr())); |
1299 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1300 | } |
1301 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1302 | (*hs_conn_p)->get_num_req_bufd())); |
1303 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1304 | (*hs_conn_p)->get_num_req_sent())); |
1305 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1306 | (*hs_conn_p)->get_num_req_rcvd())); |
1307 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1308 | (*hs_conn_p)->get_response_end_offset())); |
1309 | (*hs_conn_p)->clear_error(); |
1310 | } |
1311 | delete result; |
1312 | DBUG_RETURN(NULL); |
1313 | } |
1314 | } |
1315 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1316 | (*hs_conn_p)->get_num_req_bufd())); |
1317 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1318 | (*hs_conn_p)->get_num_req_sent())); |
1319 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1320 | (*hs_conn_p)->get_num_req_rcvd())); |
1321 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1322 | (*hs_conn_p)->get_response_end_offset())); |
1323 | (*hs_conn_p)->response_buf_remove(); |
1324 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1325 | (*hs_conn_p)->get_num_req_bufd())); |
1326 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1327 | (*hs_conn_p)->get_num_req_sent())); |
1328 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1329 | (*hs_conn_p)->get_num_req_rcvd())); |
1330 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1331 | (*hs_conn_p)->get_response_end_offset())); |
1332 | } |
1333 | if (tmp_res == -1) |
1334 | { |
1335 | DBUG_PRINT("info" ,("spider ER_SPIDER_REQUEST_KEY_NUM" )); |
1336 | *error_num = ER_SPIDER_REQUEST_KEY_NUM; |
1337 | DBUG_RETURN(NULL); |
1338 | } |
1339 | } |
1340 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1341 | (*hs_conn_p)->get_num_req_bufd())); |
1342 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1343 | (*hs_conn_p)->get_num_req_sent())); |
1344 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1345 | (*hs_conn_p)->get_num_req_rcvd())); |
1346 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1347 | (*hs_conn_p)->get_response_end_offset())); |
1348 | if ( |
1349 | (internal_error = (*hs_conn_p)->response_recv(num_fields)) || |
1350 | (*error_num = (*hs_conn_p)->get_result(hs_res_buf->hs_result)) |
1351 | ) { |
1352 | if (*error_num) |
1353 | { |
1354 | *error_num = HA_ERR_OUT_OF_MEM; |
1355 | } |
1356 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1357 | #ifndef DBUG_OFF |
1358 | if ((*hs_conn_p)->get_response_end_offset() > 0 && |
1359 | (*hs_conn_p)->get_readbuf_begin()) |
1360 | { |
1361 | char tmp_buf[MAX_FIELD_WIDTH]; |
1362 | String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); |
1363 | tmp_str.length(0); |
1364 | tmp_str.append((*hs_conn_p)->get_readbuf_begin(), |
1365 | (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); |
1366 | DBUG_PRINT("info" ,("spider hs readbuf01 size=%zu str=%s" , |
1367 | (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); |
1368 | } |
1369 | #endif |
1370 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1371 | (*hs_conn_p)->get_num_req_bufd())); |
1372 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1373 | (*hs_conn_p)->get_num_req_sent())); |
1374 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1375 | (*hs_conn_p)->get_num_req_rcvd())); |
1376 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1377 | (*hs_conn_p)->get_response_end_offset())); |
1378 | if (internal_error > 0) |
1379 | { |
1380 | (*hs_conn_p)->response_buf_remove(); |
1381 | if ((*hs_conn_p)->get_error_code()) |
1382 | { |
1383 | DBUG_PRINT("info" ,("spider hs %d %s" , |
1384 | (*hs_conn_p)->get_error_code(), |
1385 | (*hs_conn_p)->get_error().ptr())); |
1386 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1387 | } |
1388 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1389 | (*hs_conn_p)->get_num_req_bufd())); |
1390 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1391 | (*hs_conn_p)->get_num_req_sent())); |
1392 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1393 | (*hs_conn_p)->get_num_req_rcvd())); |
1394 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1395 | (*hs_conn_p)->get_response_end_offset())); |
1396 | } |
1397 | delete result; |
1398 | DBUG_RETURN(NULL); |
1399 | } |
1400 | #ifndef DBUG_OFF |
1401 | if ((*hs_conn_p)->get_response_end_offset() > 0 && |
1402 | (*hs_conn_p)->get_readbuf_begin()) |
1403 | { |
1404 | char tmp_buf[MAX_FIELD_WIDTH]; |
1405 | String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); |
1406 | tmp_str.length(0); |
1407 | tmp_str.append((*hs_conn_p)->get_readbuf_begin(), |
1408 | (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); |
1409 | DBUG_PRINT("info" ,("spider hs readbuf02 size=%zu str=%s" , |
1410 | (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); |
1411 | } |
1412 | #endif |
1413 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1414 | (*hs_conn_p)->get_num_req_bufd())); |
1415 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1416 | (*hs_conn_p)->get_num_req_sent())); |
1417 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1418 | (*hs_conn_p)->get_num_req_rcvd())); |
1419 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1420 | (*hs_conn_p)->get_response_end_offset())); |
1421 | (*hs_conn_p)->response_buf_remove(); |
1422 | if ((*hs_conn_p)->get_error_code()) |
1423 | { |
1424 | DBUG_PRINT("info" ,("spider hs %d %s" , |
1425 | (*hs_conn_p)->get_error_code(), |
1426 | (*hs_conn_p)->get_error().ptr())); |
1427 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1428 | } |
1429 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1430 | (*hs_conn_p)->get_num_req_bufd())); |
1431 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1432 | (*hs_conn_p)->get_num_req_sent())); |
1433 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1434 | (*hs_conn_p)->get_num_req_rcvd())); |
1435 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1436 | (*hs_conn_p)->get_response_end_offset())); |
1437 | field_count = (uint) num_fields; |
1438 | result->field_count = field_count; |
1439 | DBUG_RETURN(result); |
1440 | } |
1441 | |
1442 | spider_db_result *spider_db_handlersocket::use_result( |
1443 | st_spider_db_request_key *request_key, |
1444 | int *error_num |
1445 | ) { |
1446 | int internal_error; |
1447 | spider_db_handlersocket_result *result; |
1448 | DBUG_ENTER("spider_db_handlersocket::use_result" ); |
1449 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1450 | if (!(result = new spider_db_handlersocket_result(this))) |
1451 | { |
1452 | *error_num = HA_ERR_OUT_OF_MEM; |
1453 | DBUG_RETURN(NULL); |
1454 | } |
1455 | *error_num = 0; |
1456 | result->hs_conn_p = &hs_conn; |
1457 | size_t num_fields; |
1458 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1459 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1460 | if (request_key) |
1461 | { |
1462 | int tmp_res, tmp_err = (*hs_conn_p)->get_error_code(); |
1463 | while ((tmp_res = check_request_key(request_key)) == 1) |
1464 | { |
1465 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1466 | (*hs_conn_p)->get_num_req_bufd())); |
1467 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1468 | (*hs_conn_p)->get_num_req_sent())); |
1469 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1470 | (*hs_conn_p)->get_num_req_rcvd())); |
1471 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1472 | (*hs_conn_p)->get_response_end_offset())); |
1473 | if ((internal_error = (*hs_conn_p)->response_recv(num_fields))) |
1474 | { |
1475 | if (!tmp_err && internal_error > 0) |
1476 | { |
1477 | (*hs_conn_p)->clear_error(); |
1478 | } else { |
1479 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1480 | #ifndef DBUG_OFF |
1481 | if ((*hs_conn_p)->get_response_end_offset() > 0 && |
1482 | (*hs_conn_p)->get_readbuf_begin()) |
1483 | { |
1484 | char tmp_buf[MAX_FIELD_WIDTH]; |
1485 | String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); |
1486 | tmp_str.length(0); |
1487 | tmp_str.append((*hs_conn_p)->get_readbuf_begin(), |
1488 | (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); |
1489 | DBUG_PRINT("info" ,("spider hs readbuf01 size=%zu str=%s" , |
1490 | (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); |
1491 | } |
1492 | #endif |
1493 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1494 | (*hs_conn_p)->get_num_req_bufd())); |
1495 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1496 | (*hs_conn_p)->get_num_req_sent())); |
1497 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1498 | (*hs_conn_p)->get_num_req_rcvd())); |
1499 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1500 | (*hs_conn_p)->get_response_end_offset())); |
1501 | if (internal_error > 0) |
1502 | { |
1503 | (*hs_conn_p)->response_buf_remove(); |
1504 | if ((*hs_conn_p)->get_error_code()) |
1505 | { |
1506 | DBUG_PRINT("info" ,("spider hs %d %s" , |
1507 | (*hs_conn_p)->get_error_code(), |
1508 | (*hs_conn_p)->get_error().ptr())); |
1509 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1510 | } |
1511 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1512 | (*hs_conn_p)->get_num_req_bufd())); |
1513 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1514 | (*hs_conn_p)->get_num_req_sent())); |
1515 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1516 | (*hs_conn_p)->get_num_req_rcvd())); |
1517 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1518 | (*hs_conn_p)->get_response_end_offset())); |
1519 | (*hs_conn_p)->clear_error(); |
1520 | } |
1521 | delete result; |
1522 | DBUG_RETURN(NULL); |
1523 | } |
1524 | } |
1525 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1526 | (*hs_conn_p)->get_num_req_bufd())); |
1527 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1528 | (*hs_conn_p)->get_num_req_sent())); |
1529 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1530 | (*hs_conn_p)->get_num_req_rcvd())); |
1531 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1532 | (*hs_conn_p)->get_response_end_offset())); |
1533 | (*hs_conn_p)->response_buf_remove(); |
1534 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1535 | (*hs_conn_p)->get_num_req_bufd())); |
1536 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1537 | (*hs_conn_p)->get_num_req_sent())); |
1538 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1539 | (*hs_conn_p)->get_num_req_rcvd())); |
1540 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1541 | (*hs_conn_p)->get_response_end_offset())); |
1542 | } |
1543 | if (tmp_res == -1) |
1544 | { |
1545 | DBUG_PRINT("info" ,("spider ER_SPIDER_REQUEST_KEY_NUM" )); |
1546 | *error_num = ER_SPIDER_REQUEST_KEY_NUM; |
1547 | DBUG_RETURN(NULL); |
1548 | } |
1549 | } |
1550 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1551 | (*hs_conn_p)->get_num_req_bufd())); |
1552 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1553 | (*hs_conn_p)->get_num_req_sent())); |
1554 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1555 | (*hs_conn_p)->get_num_req_rcvd())); |
1556 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1557 | (*hs_conn_p)->get_response_end_offset())); |
1558 | if ( |
1559 | (internal_error = (*hs_conn_p)->response_recv(num_fields)) |
1560 | ) { |
1561 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1562 | #ifndef DBUG_OFF |
1563 | if ((*hs_conn_p)->get_response_end_offset() > 0 && |
1564 | (*hs_conn_p)->get_readbuf_begin()) |
1565 | { |
1566 | char tmp_buf[MAX_FIELD_WIDTH]; |
1567 | String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); |
1568 | tmp_str.length(0); |
1569 | tmp_str.append((*hs_conn_p)->get_readbuf_begin(), |
1570 | (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); |
1571 | DBUG_PRINT("info" ,("spider hs readbuf01 size=%zu str=%s" , |
1572 | (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); |
1573 | } |
1574 | #endif |
1575 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1576 | (*hs_conn_p)->get_num_req_bufd())); |
1577 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1578 | (*hs_conn_p)->get_num_req_sent())); |
1579 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1580 | (*hs_conn_p)->get_num_req_rcvd())); |
1581 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1582 | (*hs_conn_p)->get_response_end_offset())); |
1583 | if (internal_error > 0) |
1584 | { |
1585 | (*hs_conn_p)->response_buf_remove(); |
1586 | if ((*hs_conn_p)->get_error_code()) |
1587 | { |
1588 | DBUG_PRINT("info" ,("spider hs %d %s" , |
1589 | (*hs_conn_p)->get_error_code(), |
1590 | (*hs_conn_p)->get_error().ptr())); |
1591 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1592 | } |
1593 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1594 | (*hs_conn_p)->get_num_req_bufd())); |
1595 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1596 | (*hs_conn_p)->get_num_req_sent())); |
1597 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1598 | (*hs_conn_p)->get_num_req_rcvd())); |
1599 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1600 | (*hs_conn_p)->get_response_end_offset())); |
1601 | } |
1602 | delete result; |
1603 | DBUG_RETURN(NULL); |
1604 | } |
1605 | #ifndef DBUG_OFF |
1606 | if ((*hs_conn_p)->get_response_end_offset() > 0 && |
1607 | (*hs_conn_p)->get_readbuf_begin()) |
1608 | { |
1609 | char tmp_buf[MAX_FIELD_WIDTH]; |
1610 | String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); |
1611 | tmp_str.length(0); |
1612 | tmp_str.append((*hs_conn_p)->get_readbuf_begin(), |
1613 | (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); |
1614 | DBUG_PRINT("info" ,("spider hs readbuf02 size=%zu str=%s" , |
1615 | (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); |
1616 | } |
1617 | #endif |
1618 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1619 | (*hs_conn_p)->get_num_req_bufd())); |
1620 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1621 | (*hs_conn_p)->get_num_req_sent())); |
1622 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1623 | (*hs_conn_p)->get_num_req_rcvd())); |
1624 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1625 | (*hs_conn_p)->get_response_end_offset())); |
1626 | field_count = (uint) num_fields; |
1627 | result->field_count = field_count; |
1628 | DBUG_RETURN(result); |
1629 | } |
1630 | |
1631 | int spider_db_handlersocket::next_result() |
1632 | { |
1633 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1634 | DBUG_ENTER("spider_db_handlersocket::next_result" ); |
1635 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1636 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1637 | if ((*hs_conn_p)->stable_point()) |
1638 | DBUG_RETURN(-1); |
1639 | DBUG_RETURN(0); |
1640 | } |
1641 | |
1642 | uint spider_db_handlersocket::affected_rows() |
1643 | { |
1644 | int error_num; |
1645 | const SPIDER_HS_STRING_REF *hs_row; |
1646 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1647 | DBUG_ENTER("spider_db_handlersocket::affected_rows" ); |
1648 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1649 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1650 | if ( |
1651 | field_count != 1 || |
1652 | !(hs_row = (*hs_conn_p)->get_next_row()) || |
1653 | !hs_row->begin() |
1654 | ) { |
1655 | DBUG_RETURN(0); |
1656 | } |
1657 | DBUG_RETURN((uint) my_strtoll10(hs_row->begin(), (char**) NULL, &error_num)); |
1658 | } |
1659 | |
1660 | ulonglong spider_db_handlersocket::last_insert_id() |
1661 | { |
1662 | DBUG_ENTER("spider_db_handlersocket::last_insert_id" ); |
1663 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1664 | DBUG_RETURN(0); |
1665 | } |
1666 | |
1667 | int spider_db_handlersocket::set_character_set( |
1668 | const char *csname |
1669 | ) { |
1670 | DBUG_ENTER("spider_db_handlersocket::set_character_set" ); |
1671 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1672 | /* nothing to do */ |
1673 | DBUG_RETURN(0); |
1674 | } |
1675 | |
1676 | int spider_db_handlersocket::select_db( |
1677 | const char *dbname |
1678 | ) { |
1679 | DBUG_ENTER("spider_db_handlersocket::select_db" ); |
1680 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1681 | /* nothing to do */ |
1682 | DBUG_RETURN(0); |
1683 | } |
1684 | |
1685 | int spider_db_handlersocket::consistent_snapshot( |
1686 | int *need_mon |
1687 | ) { |
1688 | DBUG_ENTER("spider_db_handlersocket::consistent_snapshot" ); |
1689 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1690 | /* nothing to do */ |
1691 | DBUG_RETURN(0); |
1692 | } |
1693 | |
1694 | bool spider_db_handlersocket::trx_start_in_bulk_sql() |
1695 | { |
1696 | DBUG_ENTER("spider_db_handlersocket::trx_start_in_bulk_sql" ); |
1697 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1698 | DBUG_RETURN(FALSE); |
1699 | } |
1700 | |
1701 | int spider_db_handlersocket::start_transaction( |
1702 | int *need_mon |
1703 | ) { |
1704 | DBUG_ENTER("spider_db_handlersocket::start_transaction" ); |
1705 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1706 | /* nothing to do */ |
1707 | DBUG_RETURN(0); |
1708 | } |
1709 | |
1710 | int spider_db_handlersocket::commit( |
1711 | int *need_mon |
1712 | ) { |
1713 | DBUG_ENTER("spider_db_handlersocket::commit" ); |
1714 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1715 | /* nothing to do */ |
1716 | DBUG_RETURN(0); |
1717 | } |
1718 | |
1719 | int spider_db_handlersocket::rollback( |
1720 | int *need_mon |
1721 | ) { |
1722 | DBUG_ENTER("spider_db_handlersocket::rollback" ); |
1723 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1724 | /* nothing to do */ |
1725 | DBUG_RETURN(0); |
1726 | } |
1727 | |
1728 | bool spider_db_handlersocket::xa_start_in_bulk_sql() |
1729 | { |
1730 | DBUG_ENTER("spider_db_handlersocket::xa_start_in_bulk_sql" ); |
1731 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1732 | DBUG_RETURN(FALSE); |
1733 | } |
1734 | |
1735 | int spider_db_handlersocket::xa_start( |
1736 | XID *xid, |
1737 | int *need_mon |
1738 | ) { |
1739 | DBUG_ENTER("spider_db_handlersocket::xa_start" ); |
1740 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1741 | /* nothing to do */ |
1742 | DBUG_RETURN(0); |
1743 | } |
1744 | |
1745 | int spider_db_handlersocket::xa_end( |
1746 | XID *xid, |
1747 | int *need_mon |
1748 | ) { |
1749 | DBUG_ENTER("spider_db_handlersocket::xa_end" ); |
1750 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1751 | /* nothing to do */ |
1752 | DBUG_RETURN(0); |
1753 | } |
1754 | |
1755 | int spider_db_handlersocket::xa_prepare( |
1756 | XID *xid, |
1757 | int *need_mon |
1758 | ) { |
1759 | DBUG_ENTER("spider_db_handlersocket::xa_prepare" ); |
1760 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1761 | /* nothing to do */ |
1762 | DBUG_RETURN(0); |
1763 | } |
1764 | |
1765 | int spider_db_handlersocket::xa_commit( |
1766 | XID *xid, |
1767 | int *need_mon |
1768 | ) { |
1769 | DBUG_ENTER("spider_db_handlersocket::xa_commit" ); |
1770 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1771 | /* nothing to do */ |
1772 | DBUG_RETURN(0); |
1773 | } |
1774 | |
1775 | int spider_db_handlersocket::xa_rollback( |
1776 | XID *xid, |
1777 | int *need_mon |
1778 | ) { |
1779 | DBUG_ENTER("spider_db_handlersocket::xa_rollback" ); |
1780 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1781 | /* nothing to do */ |
1782 | DBUG_RETURN(0); |
1783 | } |
1784 | |
1785 | bool spider_db_handlersocket::set_trx_isolation_in_bulk_sql() |
1786 | { |
1787 | DBUG_ENTER("spider_db_handlersocket::set_trx_isolation_in_bulk_sql" ); |
1788 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1789 | DBUG_RETURN(FALSE); |
1790 | } |
1791 | |
1792 | int spider_db_handlersocket::set_trx_isolation( |
1793 | int trx_isolation, |
1794 | int *need_mon |
1795 | ) { |
1796 | DBUG_ENTER("spider_db_handlersocket::set_trx_isolation" ); |
1797 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1798 | /* nothing to do */ |
1799 | DBUG_RETURN(0); |
1800 | } |
1801 | |
1802 | bool spider_db_handlersocket::set_autocommit_in_bulk_sql() |
1803 | { |
1804 | DBUG_ENTER("spider_db_handlersocket::set_autocommit_in_bulk_sql" ); |
1805 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1806 | DBUG_RETURN(FALSE); |
1807 | } |
1808 | |
1809 | int spider_db_handlersocket::set_autocommit( |
1810 | bool autocommit, |
1811 | int *need_mon |
1812 | ) { |
1813 | DBUG_ENTER("spider_db_handlersocket::set_autocommit" ); |
1814 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1815 | /* nothing to do */ |
1816 | DBUG_RETURN(0); |
1817 | } |
1818 | |
1819 | bool spider_db_handlersocket::set_sql_log_off_in_bulk_sql() |
1820 | { |
1821 | DBUG_ENTER("spider_db_handlersocket::set_sql_log_off_in_bulk_sql" ); |
1822 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1823 | DBUG_RETURN(FALSE); |
1824 | } |
1825 | |
1826 | int spider_db_handlersocket::set_sql_log_off( |
1827 | bool sql_log_off, |
1828 | int *need_mon |
1829 | ) { |
1830 | DBUG_ENTER("spider_db_handlersocket::set_sql_log_off" ); |
1831 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1832 | /* nothing to do */ |
1833 | DBUG_RETURN(0); |
1834 | } |
1835 | |
1836 | bool spider_db_handlersocket::set_time_zone_in_bulk_sql() |
1837 | { |
1838 | DBUG_ENTER("spider_db_handlersocket::set_time_zone_in_bulk_sql" ); |
1839 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1840 | DBUG_RETURN(FALSE); |
1841 | } |
1842 | |
1843 | int spider_db_handlersocket::set_time_zone( |
1844 | Time_zone *time_zone, |
1845 | int *need_mon |
1846 | ) { |
1847 | DBUG_ENTER("spider_db_handlersocket::set_time_zone" ); |
1848 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1849 | /* nothing to do */ |
1850 | DBUG_RETURN(0); |
1851 | } |
1852 | |
1853 | int spider_db_handlersocket::show_master_status( |
1854 | SPIDER_TRX *trx, |
1855 | SPIDER_SHARE *share, |
1856 | int all_link_idx, |
1857 | int *need_mon, |
1858 | TABLE *table, |
1859 | spider_string *str, |
1860 | int mode, |
1861 | SPIDER_DB_RESULT **res1, |
1862 | SPIDER_DB_RESULT **res2 |
1863 | ) { |
1864 | DBUG_ENTER("spider_db_handlersocket::show_master_status" ); |
1865 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1866 | DBUG_RETURN(0); |
1867 | } |
1868 | |
1869 | int spider_db_handlersocket::append_sql( |
1870 | char *sql, |
1871 | ulong sql_length, |
1872 | st_spider_db_request_key *request_key |
1873 | ) { |
1874 | int error_num; |
1875 | size_t req_num; |
1876 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1877 | DBUG_ENTER("spider_db_handlersocket::append_sql" ); |
1878 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1879 | if ((error_num = append_request_key(request_key))) |
1880 | DBUG_RETURN(error_num); |
1881 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1882 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1883 | (*hs_conn_p)->get_num_req_bufd())); |
1884 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1885 | (*hs_conn_p)->get_num_req_sent())); |
1886 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1887 | (*hs_conn_p)->get_num_req_rcvd())); |
1888 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1889 | (*hs_conn_p)->get_response_end_offset())); |
1890 | if (!(req_num = (*hs_conn_p)->request_buf_append(sql, sql + sql_length))) |
1891 | { |
1892 | DBUG_PRINT("info" ,("spider hs %d %s" , |
1893 | (*hs_conn_p)->get_error_code(), |
1894 | (*hs_conn_p)->get_error().ptr())); |
1895 | (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); |
1896 | DBUG_RETURN((*hs_conn_p)->get_error_code()); |
1897 | } |
1898 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1899 | (*hs_conn_p)->get_num_req_bufd())); |
1900 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1901 | (*hs_conn_p)->get_num_req_sent())); |
1902 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1903 | (*hs_conn_p)->get_num_req_rcvd())); |
1904 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1905 | (*hs_conn_p)->get_response_end_offset())); |
1906 | while (req_num > 1) |
1907 | { |
1908 | if ((error_num = append_request_key(request_key))) |
1909 | DBUG_RETURN(error_num); |
1910 | --req_num; |
1911 | } |
1912 | DBUG_RETURN(0); |
1913 | } |
1914 | |
1915 | int spider_db_handlersocket::append_open_handler( |
1916 | uint handler_id, |
1917 | const char *db_name, |
1918 | const char *table_name, |
1919 | const char *index_name, |
1920 | const char *sql, |
1921 | st_spider_db_request_key *request_key |
1922 | ) { |
1923 | int error_num; |
1924 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1925 | DBUG_ENTER("spider_db_handlersocket::append_open_handler" ); |
1926 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1927 | if ((error_num = append_request_key(request_key))) |
1928 | DBUG_RETURN(error_num); |
1929 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1930 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1931 | (*hs_conn_p)->get_num_req_bufd())); |
1932 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1933 | (*hs_conn_p)->get_num_req_sent())); |
1934 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1935 | (*hs_conn_p)->get_num_req_rcvd())); |
1936 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1937 | (*hs_conn_p)->get_response_end_offset())); |
1938 | (*hs_conn_p)->request_buf_open_index( |
1939 | handler_id, |
1940 | db_name, |
1941 | table_name, |
1942 | index_name, |
1943 | sql |
1944 | ); |
1945 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1946 | (*hs_conn_p)->get_num_req_bufd())); |
1947 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1948 | (*hs_conn_p)->get_num_req_sent())); |
1949 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1950 | (*hs_conn_p)->get_num_req_rcvd())); |
1951 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1952 | (*hs_conn_p)->get_response_end_offset())); |
1953 | DBUG_RETURN(0); |
1954 | } |
1955 | |
1956 | int spider_db_handlersocket::append_select( |
1957 | uint handler_id, |
1958 | spider_string *sql, |
1959 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
1960 | int limit, |
1961 | int skip, |
1962 | st_spider_db_request_key *request_key |
1963 | ) { |
1964 | int error_num; |
1965 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
1966 | DBUG_ENTER("spider_db_handlersocket::append_select" ); |
1967 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1968 | if ((error_num = append_request_key(request_key))) |
1969 | DBUG_RETURN(error_num); |
1970 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
1971 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1972 | (*hs_conn_p)->get_num_req_bufd())); |
1973 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1974 | (*hs_conn_p)->get_num_req_sent())); |
1975 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1976 | (*hs_conn_p)->get_num_req_rcvd())); |
1977 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1978 | (*hs_conn_p)->get_response_end_offset())); |
1979 | (*hs_conn_p)->request_buf_exec_generic( |
1980 | handler_id, |
1981 | SPIDER_HS_STRING_REF(sql->ptr(), sql->length()), |
1982 | keys->ptr(), (size_t) keys->size(), |
1983 | limit, skip, |
1984 | SPIDER_HS_STRING_REF(), |
1985 | NULL, 0); |
1986 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
1987 | (*hs_conn_p)->get_num_req_bufd())); |
1988 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
1989 | (*hs_conn_p)->get_num_req_sent())); |
1990 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
1991 | (*hs_conn_p)->get_num_req_rcvd())); |
1992 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
1993 | (*hs_conn_p)->get_response_end_offset())); |
1994 | DBUG_RETURN(0); |
1995 | } |
1996 | |
1997 | int spider_db_handlersocket::append_insert( |
1998 | uint handler_id, |
1999 | SPIDER_DB_HS_STRING_REF_BUFFER *upds, |
2000 | st_spider_db_request_key *request_key |
2001 | ) { |
2002 | int error_num; |
2003 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
2004 | DBUG_ENTER("spider_db_handlersocket::append_insert" ); |
2005 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2006 | if ((error_num = append_request_key(request_key))) |
2007 | DBUG_RETURN(error_num); |
2008 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
2009 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2010 | (*hs_conn_p)->get_num_req_bufd())); |
2011 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2012 | (*hs_conn_p)->get_num_req_sent())); |
2013 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2014 | (*hs_conn_p)->get_num_req_rcvd())); |
2015 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2016 | (*hs_conn_p)->get_response_end_offset())); |
2017 | (*hs_conn_p)->request_buf_exec_generic( |
2018 | handler_id, |
2019 | SPIDER_HS_STRING_REF(SPIDER_SQL_HS_INSERT_STR, SPIDER_SQL_HS_INSERT_LEN), |
2020 | upds->ptr(), (size_t) upds->size(), |
2021 | 0, 0, |
2022 | SPIDER_HS_STRING_REF(), NULL, 0); |
2023 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2024 | (*hs_conn_p)->get_num_req_bufd())); |
2025 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2026 | (*hs_conn_p)->get_num_req_sent())); |
2027 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2028 | (*hs_conn_p)->get_num_req_rcvd())); |
2029 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2030 | (*hs_conn_p)->get_response_end_offset())); |
2031 | DBUG_RETURN(0); |
2032 | } |
2033 | |
2034 | int spider_db_handlersocket::append_update( |
2035 | uint handler_id, |
2036 | spider_string *sql, |
2037 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
2038 | SPIDER_DB_HS_STRING_REF_BUFFER *upds, |
2039 | int limit, |
2040 | int skip, |
2041 | bool increment, |
2042 | bool decrement, |
2043 | st_spider_db_request_key *request_key |
2044 | ) { |
2045 | int error_num; |
2046 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
2047 | DBUG_ENTER("spider_db_handlersocket::append_update" ); |
2048 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2049 | if ((error_num = append_request_key(request_key))) |
2050 | DBUG_RETURN(error_num); |
2051 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
2052 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2053 | (*hs_conn_p)->get_num_req_bufd())); |
2054 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2055 | (*hs_conn_p)->get_num_req_sent())); |
2056 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2057 | (*hs_conn_p)->get_num_req_rcvd())); |
2058 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2059 | (*hs_conn_p)->get_response_end_offset())); |
2060 | (*hs_conn_p)->request_buf_exec_generic( |
2061 | handler_id, |
2062 | SPIDER_HS_STRING_REF(sql->ptr(), sql->length()), |
2063 | keys->ptr(), (size_t) keys->size(), |
2064 | limit, skip, |
2065 | increment ? |
2066 | SPIDER_HS_STRING_REF(SPIDER_SQL_HS_INCREMENT_STR, |
2067 | SPIDER_SQL_HS_INCREMENT_LEN) : |
2068 | decrement ? |
2069 | SPIDER_HS_STRING_REF(SPIDER_SQL_HS_DECREMENT_STR, |
2070 | SPIDER_SQL_HS_DECREMENT_LEN) : |
2071 | SPIDER_HS_STRING_REF(SPIDER_SQL_HS_UPDATE_STR, |
2072 | SPIDER_SQL_HS_UPDATE_LEN), |
2073 | upds->ptr(), (size_t) upds->size() |
2074 | ); |
2075 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2076 | (*hs_conn_p)->get_num_req_bufd())); |
2077 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2078 | (*hs_conn_p)->get_num_req_sent())); |
2079 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2080 | (*hs_conn_p)->get_num_req_rcvd())); |
2081 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2082 | (*hs_conn_p)->get_response_end_offset())); |
2083 | DBUG_RETURN(0); |
2084 | } |
2085 | |
2086 | int spider_db_handlersocket::append_delete( |
2087 | uint handler_id, |
2088 | spider_string *sql, |
2089 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
2090 | int limit, |
2091 | int skip, |
2092 | st_spider_db_request_key *request_key |
2093 | ) { |
2094 | int error_num; |
2095 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
2096 | DBUG_ENTER("spider_db_handlersocket::append_delete" ); |
2097 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2098 | if ((error_num = append_request_key(request_key))) |
2099 | DBUG_RETURN(error_num); |
2100 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
2101 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2102 | (*hs_conn_p)->get_num_req_bufd())); |
2103 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2104 | (*hs_conn_p)->get_num_req_sent())); |
2105 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2106 | (*hs_conn_p)->get_num_req_rcvd())); |
2107 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2108 | (*hs_conn_p)->get_response_end_offset())); |
2109 | (*hs_conn_p)->request_buf_exec_generic( |
2110 | handler_id, |
2111 | SPIDER_HS_STRING_REF(sql->ptr(), sql->length()), |
2112 | keys->ptr(), (size_t) keys->size(), |
2113 | limit, skip, |
2114 | SPIDER_HS_STRING_REF(SPIDER_SQL_HS_DELETE_STR, SPIDER_SQL_HS_DELETE_LEN), |
2115 | NULL, 0); |
2116 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2117 | (*hs_conn_p)->get_num_req_bufd())); |
2118 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2119 | (*hs_conn_p)->get_num_req_sent())); |
2120 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2121 | (*hs_conn_p)->get_num_req_rcvd())); |
2122 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2123 | (*hs_conn_p)->get_response_end_offset())); |
2124 | DBUG_RETURN(0); |
2125 | } |
2126 | |
2127 | void spider_db_handlersocket::reset_request_queue() |
2128 | { |
2129 | SPIDER_HS_CONN *hs_conn_p = &hs_conn; |
2130 | DBUG_ENTER("spider_db_handlersocket::reset_request_queue" ); |
2131 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2132 | DBUG_PRINT("info" ,("spider hs hs_conn=%p" , hs_conn_p)); |
2133 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2134 | (*hs_conn_p)->get_num_req_bufd())); |
2135 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2136 | (*hs_conn_p)->get_num_req_sent())); |
2137 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2138 | (*hs_conn_p)->get_num_req_rcvd())); |
2139 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2140 | (*hs_conn_p)->get_response_end_offset())); |
2141 | (*hs_conn_p)->request_reset(); |
2142 | DBUG_PRINT("info" ,("spider hs num_req_bufd=%zu" , |
2143 | (*hs_conn_p)->get_num_req_bufd())); |
2144 | DBUG_PRINT("info" ,("spider hs num_req_sent=%zu" , |
2145 | (*hs_conn_p)->get_num_req_sent())); |
2146 | DBUG_PRINT("info" ,("spider hs num_req_rcvd=%zu" , |
2147 | (*hs_conn_p)->get_num_req_rcvd())); |
2148 | DBUG_PRINT("info" ,("spider hs response_end_offset=%zu" , |
2149 | (*hs_conn_p)->get_response_end_offset())); |
2150 | reset_request_key_req(); |
2151 | DBUG_VOID_RETURN; |
2152 | } |
2153 | |
2154 | size_t spider_db_handlersocket::escape_string( |
2155 | char *to, |
2156 | const char *from, |
2157 | size_t from_length |
2158 | ) { |
2159 | DBUG_ENTER("spider_db_handlersocket::escape_string" ); |
2160 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2161 | DBUG_ASSERT(0); |
2162 | memcpy(to, from, from_length); |
2163 | DBUG_RETURN(from_length); |
2164 | } |
2165 | |
2166 | bool spider_db_handlersocket::have_lock_table_list() |
2167 | { |
2168 | DBUG_ENTER("spider_db_handlersocket::have_lock_table_list" ); |
2169 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2170 | DBUG_RETURN(FALSE); |
2171 | } |
2172 | |
2173 | int spider_db_handlersocket::append_lock_tables( |
2174 | spider_string *str |
2175 | ) { |
2176 | DBUG_ENTER("spider_db_handlersocket::lock_tables" ); |
2177 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2178 | DBUG_RETURN(0); |
2179 | } |
2180 | |
2181 | int spider_db_handlersocket::append_unlock_tables( |
2182 | spider_string *str |
2183 | ) { |
2184 | DBUG_ENTER("spider_db_handlersocket::append_unlock_tables" ); |
2185 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2186 | DBUG_RETURN(0); |
2187 | } |
2188 | |
2189 | uint spider_db_handlersocket::get_lock_table_hash_count() |
2190 | { |
2191 | DBUG_ENTER("spider_db_handlersocket::get_lock_table_hash_count" ); |
2192 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2193 | DBUG_ASSERT(0); |
2194 | DBUG_RETURN(0); |
2195 | } |
2196 | |
2197 | void spider_db_handlersocket::reset_lock_table_hash() |
2198 | { |
2199 | DBUG_ENTER("spider_db_handlersocket::reset_lock_table_hash" ); |
2200 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2201 | DBUG_ASSERT(0); |
2202 | DBUG_VOID_RETURN; |
2203 | } |
2204 | |
2205 | uint spider_db_handlersocket::get_opened_handler_count() |
2206 | { |
2207 | DBUG_ENTER("spider_db_handlersocket::get_opened_handler_count" ); |
2208 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2209 | DBUG_RETURN(handler_open_array.elements); |
2210 | } |
2211 | |
2212 | void spider_db_handlersocket::reset_opened_handler() |
2213 | { |
2214 | ha_spider *tmp_spider; |
2215 | int tmp_link_idx; |
2216 | SPIDER_LINK_FOR_HASH **tmp_link_for_hash; |
2217 | DBUG_ENTER("spider_db_handlersocket::reset_opened_handler" ); |
2218 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2219 | while ((tmp_link_for_hash = |
2220 | (SPIDER_LINK_FOR_HASH **) pop_dynamic(&handler_open_array))) |
2221 | { |
2222 | tmp_spider = (*tmp_link_for_hash)->spider; |
2223 | tmp_link_idx = (*tmp_link_for_hash)->link_idx; |
2224 | tmp_spider->clear_handler_opened(tmp_link_idx, conn->conn_kind); |
2225 | } |
2226 | DBUG_VOID_RETURN; |
2227 | } |
2228 | |
2229 | void spider_db_handlersocket::set_dup_key_idx( |
2230 | ha_spider *spider, |
2231 | int link_idx |
2232 | ) { |
2233 | DBUG_ENTER("spider_db_handlersocket::set_dup_key_idx" ); |
2234 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2235 | DBUG_ASSERT(0); |
2236 | DBUG_VOID_RETURN; |
2237 | } |
2238 | |
2239 | int spider_db_handlersocket::append_request_key( |
2240 | st_spider_db_request_key *request_key |
2241 | ) { |
2242 | st_spider_db_request_key *tmp_request_key; |
2243 | DBUG_ENTER("spider_db_handlersocket::append_request_key" ); |
2244 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2245 | DBUG_PRINT("info" ,("spider request_key=%p" , request_key)); |
2246 | if (request_key) |
2247 | { |
2248 | DBUG_PRINT("info" ,("spider request_key->spider_thread_id=%llu" , |
2249 | request_key->spider_thread_id)); |
2250 | DBUG_PRINT("info" ,("spider request_key->query_id=%llu" , |
2251 | request_key->query_id)); |
2252 | DBUG_PRINT("info" ,("spider request_key->handler=%p" , |
2253 | request_key->handler)); |
2254 | DBUG_PRINT("info" ,("spider request_key->request_id=%llu" , |
2255 | request_key->request_id)); |
2256 | if (request_key_reuse_first) |
2257 | { |
2258 | tmp_request_key = request_key_reuse_first; |
2259 | request_key_reuse_first = request_key_reuse_first->next; |
2260 | if (!request_key_reuse_first) |
2261 | request_key_reuse_last = NULL; |
2262 | } else { |
2263 | if (!(tmp_request_key = (st_spider_db_request_key *) |
2264 | spider_malloc(spider_current_trx, 1, sizeof(st_spider_db_request_key), |
2265 | MYF(MY_WME))) |
2266 | ) |
2267 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2268 | } |
2269 | *tmp_request_key = *request_key; |
2270 | tmp_request_key->next = NULL; |
2271 | if (request_key_req_last) |
2272 | request_key_req_last->next = tmp_request_key; |
2273 | else |
2274 | request_key_req_first = tmp_request_key; |
2275 | request_key_req_last = tmp_request_key; |
2276 | } |
2277 | DBUG_RETURN(0); |
2278 | } |
2279 | |
2280 | void spider_db_handlersocket::reset_request_key_req() |
2281 | { |
2282 | DBUG_ENTER("spider_db_handlersocket::reset_request_key_req" ); |
2283 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2284 | if (request_key_req_first) |
2285 | { |
2286 | if (request_key_reuse_last) |
2287 | request_key_reuse_last->next = request_key_req_first; |
2288 | else |
2289 | request_key_reuse_first = request_key_req_first; |
2290 | request_key_reuse_last = request_key_req_last; |
2291 | request_key_req_first = NULL; |
2292 | request_key_req_last = NULL; |
2293 | } |
2294 | DBUG_VOID_RETURN; |
2295 | } |
2296 | |
2297 | void spider_db_handlersocket::reset_request_key_snd() |
2298 | { |
2299 | DBUG_ENTER("spider_db_handlersocket::reset_request_key_snd" ); |
2300 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2301 | if (request_key_snd_first) |
2302 | { |
2303 | if (request_key_reuse_last) |
2304 | request_key_reuse_last->next = request_key_snd_first; |
2305 | else |
2306 | request_key_reuse_first = request_key_snd_first; |
2307 | request_key_reuse_last = request_key_snd_last; |
2308 | request_key_snd_first = NULL; |
2309 | request_key_snd_last = NULL; |
2310 | } |
2311 | DBUG_VOID_RETURN; |
2312 | } |
2313 | |
2314 | void spider_db_handlersocket::move_request_key_to_snd() |
2315 | { |
2316 | DBUG_ENTER("spider_db_handlersocket::move_request_key_to_snd" ); |
2317 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2318 | if (request_key_req_first) |
2319 | { |
2320 | if (request_key_snd_last) |
2321 | request_key_snd_last->next = request_key_req_first; |
2322 | else |
2323 | request_key_snd_first = request_key_req_first; |
2324 | request_key_snd_last = request_key_req_last; |
2325 | request_key_req_first = NULL; |
2326 | request_key_req_last = NULL; |
2327 | } |
2328 | DBUG_VOID_RETURN; |
2329 | } |
2330 | |
2331 | int spider_db_handlersocket::check_request_key( |
2332 | st_spider_db_request_key *request_key |
2333 | ) { |
2334 | st_spider_db_request_key *tmp_request_key; |
2335 | DBUG_ENTER("spider_db_handlersocket::check_request_key" ); |
2336 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2337 | DBUG_PRINT("info" ,("spider request_key=%p" , request_key)); |
2338 | DBUG_PRINT("info" ,("spider request_key_snd_first=%p" , |
2339 | request_key_snd_first)); |
2340 | if (!request_key_snd_first) |
2341 | { |
2342 | DBUG_PRINT("info" ,("spider -1" )); |
2343 | DBUG_RETURN(-1); |
2344 | } |
2345 | tmp_request_key = request_key_snd_first; |
2346 | request_key_snd_first = request_key_snd_first->next; |
2347 | if (!request_key_snd_first) |
2348 | request_key_snd_last = NULL; |
2349 | tmp_request_key->next = NULL; |
2350 | if (request_key_reuse_last) |
2351 | request_key_reuse_last->next = tmp_request_key; |
2352 | else |
2353 | request_key_reuse_first = tmp_request_key; |
2354 | request_key_reuse_last = tmp_request_key; |
2355 | |
2356 | DBUG_PRINT("info" ,("spider tmp_request_key->spider_thread_id=%llu" , |
2357 | tmp_request_key->spider_thread_id)); |
2358 | DBUG_PRINT("info" ,("spider request_key->spider_thread_id=%llu" , |
2359 | request_key->spider_thread_id)); |
2360 | DBUG_PRINT("info" ,("spider tmp_request_key->query_id=%llu" , |
2361 | tmp_request_key->query_id)); |
2362 | DBUG_PRINT("info" ,("spider request_key->query_id=%llu" , |
2363 | request_key->query_id)); |
2364 | DBUG_PRINT("info" ,("spider tmp_request_key->handler=%p" , |
2365 | tmp_request_key->handler)); |
2366 | DBUG_PRINT("info" ,("spider request_key->handler=%p" , |
2367 | request_key->handler)); |
2368 | DBUG_PRINT("info" ,("spider tmp_request_key->request_id=%llu" , |
2369 | tmp_request_key->request_id)); |
2370 | DBUG_PRINT("info" ,("spider request_key->request_id=%llu" , |
2371 | request_key->request_id)); |
2372 | if ( |
2373 | tmp_request_key->spider_thread_id != request_key->spider_thread_id || |
2374 | tmp_request_key->query_id != request_key->query_id || |
2375 | tmp_request_key->handler != request_key->handler || |
2376 | tmp_request_key->request_id != request_key->request_id |
2377 | ) { |
2378 | DBUG_PRINT("info" ,("spider 1" )); |
2379 | DBUG_RETURN(1); |
2380 | } |
2381 | DBUG_PRINT("info" ,("spider 0" )); |
2382 | DBUG_RETURN(0); |
2383 | } |
2384 | |
2385 | bool spider_db_handlersocket::cmp_request_key_to_snd( |
2386 | st_spider_db_request_key *request_key |
2387 | ) { |
2388 | DBUG_ENTER("spider_db_handlersocket::cmp_request_key_to_snd" ); |
2389 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2390 | DBUG_PRINT("info" ,("spider request_key=%p" , request_key)); |
2391 | if ( |
2392 | !request_key |
2393 | ) { |
2394 | DBUG_PRINT("info" ,("spider TRUE" )); |
2395 | DBUG_RETURN(TRUE); |
2396 | } |
2397 | DBUG_PRINT("info" ,("spider request_key_snd_first=%p" , |
2398 | request_key_snd_first)); |
2399 | if ( |
2400 | !request_key_snd_first |
2401 | ) { |
2402 | DBUG_PRINT("info" ,("spider FALSE" )); |
2403 | DBUG_RETURN(FALSE); |
2404 | } |
2405 | DBUG_PRINT("info" ,("spider request_key_snd_first->spider_thread_id=%llu" , |
2406 | request_key_snd_first->spider_thread_id)); |
2407 | DBUG_PRINT("info" ,("spider request_key->spider_thread_id=%llu" , |
2408 | request_key->spider_thread_id)); |
2409 | DBUG_PRINT("info" ,("spider request_key_snd_first->query_id=%llu" , |
2410 | request_key_snd_first->query_id)); |
2411 | DBUG_PRINT("info" ,("spider request_key->query_id=%llu" , |
2412 | request_key->query_id)); |
2413 | DBUG_PRINT("info" ,("spider request_key_snd_first->handler=%p" , |
2414 | request_key_snd_first->handler)); |
2415 | DBUG_PRINT("info" ,("spider request_key->handler=%p" , |
2416 | request_key->handler)); |
2417 | DBUG_PRINT("info" ,("spider request_key_snd_first->request_id=%llu" , |
2418 | request_key_snd_first->request_id)); |
2419 | DBUG_PRINT("info" ,("spider request_key->request_id=%llu" , |
2420 | request_key->request_id)); |
2421 | if ( |
2422 | request_key_snd_first->spider_thread_id != request_key->spider_thread_id || |
2423 | request_key_snd_first->query_id != request_key->query_id || |
2424 | request_key_snd_first->handler != request_key->handler || |
2425 | request_key_snd_first->request_id != request_key->request_id |
2426 | ) { |
2427 | DBUG_PRINT("info" ,("spider FALSE" )); |
2428 | DBUG_RETURN(FALSE); |
2429 | } |
2430 | DBUG_PRINT("info" ,("spider TRUE" )); |
2431 | DBUG_RETURN(TRUE); |
2432 | } |
2433 | |
2434 | spider_db_handlersocket_util::spider_db_handlersocket_util() : spider_db_util() |
2435 | { |
2436 | DBUG_ENTER("spider_db_handlersocket_util::spider_db_handlersocket_util" ); |
2437 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2438 | DBUG_VOID_RETURN; |
2439 | } |
2440 | |
2441 | spider_db_handlersocket_util::~spider_db_handlersocket_util() |
2442 | { |
2443 | DBUG_ENTER("spider_db_handlersocket_util::~spider_db_handlersocket_util" ); |
2444 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2445 | DBUG_VOID_RETURN; |
2446 | } |
2447 | |
2448 | int spider_db_handlersocket_util::append_name( |
2449 | spider_string *str, |
2450 | const char *name, |
2451 | uint name_length |
2452 | ) { |
2453 | DBUG_ENTER("spider_db_handlersocket_util::append_name" ); |
2454 | str->q_append(name, name_length); |
2455 | DBUG_RETURN(0); |
2456 | } |
2457 | |
2458 | int spider_db_handlersocket_util::append_name_with_charset( |
2459 | spider_string *str, |
2460 | const char *name, |
2461 | uint name_length, |
2462 | CHARSET_INFO *name_charset |
2463 | ) { |
2464 | DBUG_ENTER("spider_db_handlersocket_util::append_name_with_charset" ); |
2465 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2 + name_length * 2)) |
2466 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2467 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2468 | str->append(name, name_length, name_charset); |
2469 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) |
2470 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2471 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2472 | DBUG_RETURN(0); |
2473 | } |
2474 | |
2475 | bool spider_db_handlersocket_util::is_name_quote( |
2476 | const char head_code |
2477 | ) { |
2478 | DBUG_ENTER("spider_db_handlersocket_util::is_name_quote" ); |
2479 | DBUG_RETURN(head_code == *name_quote_str); |
2480 | } |
2481 | |
2482 | int spider_db_handlersocket_util::append_escaped_name_quote( |
2483 | spider_string *str |
2484 | ) { |
2485 | DBUG_ENTER("spider_db_handlersocket_util::append_escaped_name_quote" ); |
2486 | if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2)) |
2487 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2488 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2489 | str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); |
2490 | DBUG_RETURN(0); |
2491 | } |
2492 | |
2493 | int spider_db_handlersocket_util::append_column_value( |
2494 | ha_spider *spider, |
2495 | spider_string *str, |
2496 | Field *field, |
2497 | const uchar *new_ptr, |
2498 | CHARSET_INFO *access_charset |
2499 | ) { |
2500 | char buf[MAX_FIELD_WIDTH]; |
2501 | spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); |
2502 | String *ptr; |
2503 | uint length; |
2504 | DBUG_ENTER("spider_db_handlersocket_util::append_column_value" ); |
2505 | tmp_str.init_calc_mem(180); |
2506 | |
2507 | if (new_ptr) |
2508 | { |
2509 | if ( |
2510 | field->type() == MYSQL_TYPE_BLOB || |
2511 | field->real_type() == MYSQL_TYPE_VARCHAR |
2512 | ) { |
2513 | length = uint2korr(new_ptr); |
2514 | tmp_str.set_quick((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, |
2515 | &my_charset_bin); |
2516 | ptr = tmp_str.get_str(); |
2517 | } else if (field->type() == MYSQL_TYPE_GEOMETRY) |
2518 | { |
2519 | /* |
2520 | uint mlength = SIZEOF_STORED_DOUBLE, lcnt; |
2521 | uchar *dest = (uchar *) buf; |
2522 | const uchar *source; |
2523 | for (lcnt = 0; lcnt < 4; lcnt++) |
2524 | { |
2525 | mlength = SIZEOF_STORED_DOUBLE; |
2526 | source = new_ptr + mlength + SIZEOF_STORED_DOUBLE * lcnt; |
2527 | while (mlength--) |
2528 | *dest++ = *--source; |
2529 | } |
2530 | tmp_str.length(SIZEOF_STORED_DOUBLE * lcnt); |
2531 | */ |
2532 | double xmin, xmax, ymin, ymax; |
2533 | /* |
2534 | float8store(buf,xmin); |
2535 | float8store(buf+8,xmax); |
2536 | float8store(buf+16,ymin); |
2537 | float8store(buf+24,ymax); |
2538 | memcpy(&xmin,new_ptr,sizeof(xmin)); |
2539 | memcpy(&xmax,new_ptr + 8,sizeof(xmax)); |
2540 | memcpy(&ymin,new_ptr + 16,sizeof(ymin)); |
2541 | memcpy(&ymax,new_ptr + 24,sizeof(ymax)); |
2542 | float8get(xmin, buf); |
2543 | float8get(xmax, buf + 8); |
2544 | float8get(ymin, buf + 16); |
2545 | float8get(ymax, buf + 24); |
2546 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2547 | xmin, xmax, ymin, ymax)); |
2548 | DBUG_PRINT("info", ("spider geo is %.14g %.14g %.14g %.14g", |
2549 | xmin, xmax, ymin, ymax)); |
2550 | */ |
2551 | float8get(xmin, new_ptr); |
2552 | float8get(xmax, new_ptr + 8); |
2553 | float8get(ymin, new_ptr + 16); |
2554 | float8get(ymax, new_ptr + 24); |
2555 | DBUG_PRINT("info" , ("spider geo is %f %f %f %f" , |
2556 | xmin, xmax, ymin, ymax)); |
2557 | /* |
2558 | float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 4); |
2559 | float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 5); |
2560 | float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 6); |
2561 | float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 7); |
2562 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2563 | xmin, xmax, ymin, ymax)); |
2564 | float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 8); |
2565 | float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 9); |
2566 | float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 10); |
2567 | float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 11); |
2568 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2569 | xmin, xmax, ymin, ymax)); |
2570 | float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 12); |
2571 | float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 13); |
2572 | float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 14); |
2573 | float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 15); |
2574 | DBUG_PRINT("info", ("spider geo is %f %f %f %f", |
2575 | xmin, xmax, ymin, ymax)); |
2576 | */ |
2577 | /* |
2578 | tmp_str.set_quick((char *) new_ptr, SIZEOF_STORED_DOUBLE * 4, |
2579 | &my_charset_bin); |
2580 | */ |
2581 | tmp_str.length(0); |
2582 | tmp_str.q_append((char *) SPIDER_SQL_LINESTRING_HEAD_STR, |
2583 | SPIDER_SQL_LINESTRING_HEAD_LEN); |
2584 | tmp_str.q_append((char *) new_ptr, SIZEOF_STORED_DOUBLE); |
2585 | tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 2, |
2586 | SIZEOF_STORED_DOUBLE); |
2587 | tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE, |
2588 | SIZEOF_STORED_DOUBLE); |
2589 | tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 3, |
2590 | SIZEOF_STORED_DOUBLE); |
2591 | ptr = tmp_str.get_str(); |
2592 | } else { |
2593 | ptr = field->val_str(tmp_str.get_str(), new_ptr); |
2594 | tmp_str.mem_calc(); |
2595 | } |
2596 | } else { |
2597 | ptr = field->val_str(tmp_str.get_str()); |
2598 | tmp_str.mem_calc(); |
2599 | } |
2600 | DBUG_PRINT("info" , ("spider field->type() is %d" , field->type())); |
2601 | DBUG_PRINT("info" , ("spider ptr->length() is %d" , ptr->length())); |
2602 | /* |
2603 | if ( |
2604 | field->type() == MYSQL_TYPE_BIT || |
2605 | (field->type() >= MYSQL_TYPE_TINY_BLOB && |
2606 | field->type() <= MYSQL_TYPE_BLOB) |
2607 | ) { |
2608 | uchar *hex_ptr = (uchar *) ptr->ptr(), *end_ptr; |
2609 | char *str_ptr; |
2610 | DBUG_PRINT("info", ("spider HEX")); |
2611 | if (str->reserve(SPIDER_SQL_HEX_LEN + ptr->length() * 2)) |
2612 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2613 | str->q_append(SPIDER_SQL_HEX_STR, SPIDER_SQL_HEX_LEN); |
2614 | str_ptr = (char *) str->ptr() + str->length(); |
2615 | for (end_ptr = hex_ptr + ptr->length(); hex_ptr < end_ptr; hex_ptr++) |
2616 | { |
2617 | *str_ptr++ = spider_dig_upper[(*hex_ptr) >> 4]; |
2618 | *str_ptr++ = spider_dig_upper[(*hex_ptr) & 0x0F]; |
2619 | } |
2620 | str->length(str->length() + ptr->length() * 2); |
2621 | } else |
2622 | */ |
2623 | spider_handlersocket_handler *hs_handler = (spider_handlersocket_handler *) |
2624 | spider->dbton_handler[spider_dbton_handlersocket.dbton_id]; |
2625 | spider_string *hs_str; |
2626 | if (!(hs_str = hs_handler->hs_strs.add( |
2627 | &hs_handler->hs_strs_pos, ptr->ptr(), ptr->length()))) |
2628 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2629 | SPIDER_HS_STRING_REF ref = |
2630 | SPIDER_HS_STRING_REF(hs_str->ptr(), hs_str->length()); |
2631 | if (hs_handler->hs_adding_keys) |
2632 | { |
2633 | DBUG_PRINT("info" , ("spider add to key:%s" , hs_str->c_ptr_safe())); |
2634 | hs_handler->hs_keys.push_back(ref); |
2635 | } else { |
2636 | DBUG_PRINT("info" , ("spider add to upd:%s" , hs_str->c_ptr_safe())); |
2637 | hs_handler->hs_upds.push_back(ref); |
2638 | } |
2639 | DBUG_RETURN(0); |
2640 | } |
2641 | |
2642 | int spider_db_handlersocket_util::append_trx_isolation( |
2643 | spider_string *str, |
2644 | int trx_isolation |
2645 | ) { |
2646 | DBUG_ENTER("spider_db_handlersocket_util::append_trx_isolation" ); |
2647 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2648 | /* nothing to do */ |
2649 | DBUG_RETURN(0); |
2650 | } |
2651 | |
2652 | int spider_db_handlersocket_util::append_autocommit( |
2653 | spider_string *str, |
2654 | bool autocommit |
2655 | ) { |
2656 | DBUG_ENTER("spider_db_handlersocket_util::append_autocommit" ); |
2657 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2658 | /* nothing to do */ |
2659 | DBUG_RETURN(0); |
2660 | } |
2661 | |
2662 | int spider_db_handlersocket_util::append_sql_log_off( |
2663 | spider_string *str, |
2664 | bool sql_log_off |
2665 | ) { |
2666 | DBUG_ENTER("spider_db_handlersocket_util::append_sql_log_off" ); |
2667 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2668 | /* nothing to do */ |
2669 | DBUG_RETURN(0); |
2670 | } |
2671 | |
2672 | int spider_db_handlersocket_util::append_time_zone( |
2673 | spider_string *str, |
2674 | Time_zone *time_zone |
2675 | ) { |
2676 | DBUG_ENTER("spider_db_handlersocket_util::append_time_zone" ); |
2677 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2678 | /* nothing to do */ |
2679 | DBUG_RETURN(0); |
2680 | } |
2681 | |
2682 | int spider_db_handlersocket_util::append_start_transaction( |
2683 | spider_string *str |
2684 | ) { |
2685 | DBUG_ENTER("spider_db_handlersocket_util::append_start_transaction" ); |
2686 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2687 | /* nothing to do */ |
2688 | DBUG_RETURN(0); |
2689 | } |
2690 | |
2691 | int spider_db_handlersocket_util::append_xa_start( |
2692 | spider_string *str, |
2693 | XID *xid |
2694 | ) { |
2695 | DBUG_ENTER("spider_db_handlersocket_util::append_xa_start" ); |
2696 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2697 | /* nothing to do */ |
2698 | DBUG_RETURN(0); |
2699 | } |
2700 | |
2701 | int spider_db_handlersocket_util::append_lock_table_head( |
2702 | spider_string *str |
2703 | ) { |
2704 | DBUG_ENTER("spider_db_handlersocket_util::append_lock_table_head" ); |
2705 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2706 | /* nothing to do */ |
2707 | DBUG_RETURN(0); |
2708 | } |
2709 | |
2710 | int spider_db_handlersocket_util::append_lock_table_body( |
2711 | spider_string *str, |
2712 | const char *db_name, |
2713 | uint db_name_length, |
2714 | CHARSET_INFO *db_name_charset, |
2715 | const char *table_name, |
2716 | uint table_name_length, |
2717 | CHARSET_INFO *table_name_charset, |
2718 | int lock_type |
2719 | ) { |
2720 | DBUG_ENTER("spider_db_handlersocket_util::append_lock_table_body" ); |
2721 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2722 | /* nothing to do */ |
2723 | DBUG_RETURN(0); |
2724 | } |
2725 | |
2726 | int spider_db_handlersocket_util::append_lock_table_tail( |
2727 | spider_string *str |
2728 | ) { |
2729 | DBUG_ENTER("spider_db_handlersocket_util::append_lock_table_tail" ); |
2730 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2731 | /* nothing to do */ |
2732 | DBUG_RETURN(0); |
2733 | } |
2734 | |
2735 | int spider_db_handlersocket_util::append_unlock_table( |
2736 | spider_string *str |
2737 | ) { |
2738 | DBUG_ENTER("spider_db_handlersocket_util::append_unlock_table" ); |
2739 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
2740 | /* nothing to do */ |
2741 | DBUG_RETURN(0); |
2742 | } |
2743 | |
2744 | int spider_db_handlersocket_util::open_item_func( |
2745 | Item_func *item_func, |
2746 | ha_spider *spider, |
2747 | spider_string *str, |
2748 | const char *alias, |
2749 | uint alias_length, |
2750 | bool use_fields, |
2751 | spider_fields *fields |
2752 | ) { |
2753 | uint dbton_id = spider_dbton_handlersocket.dbton_id; |
2754 | int error_num; |
2755 | Item *item, **item_list = item_func->arguments(); |
2756 | uint roop_count, item_count = item_func->argument_count(), start_item = 0; |
2757 | const char *func_name = SPIDER_SQL_NULL_CHAR_STR, |
2758 | *separete_str = SPIDER_SQL_NULL_CHAR_STR, |
2759 | *last_str = SPIDER_SQL_NULL_CHAR_STR; |
2760 | int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, |
2761 | separete_str_length = SPIDER_SQL_NULL_CHAR_LEN, |
2762 | last_str_length = SPIDER_SQL_NULL_CHAR_LEN; |
2763 | int use_pushdown_udf; |
2764 | bool merge_func = FALSE; |
2765 | DBUG_ENTER("spider_db_handlersocket_util::open_item_func" ); |
2766 | if (str) |
2767 | { |
2768 | if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) |
2769 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2770 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
2771 | } |
2772 | DBUG_PRINT("info" ,("spider functype = %d" , item_func->functype())); |
2773 | switch (item_func->functype()) |
2774 | { |
2775 | case Item_func::ISNULL_FUNC: |
2776 | last_str = SPIDER_SQL_IS_NULL_STR; |
2777 | last_str_length = SPIDER_SQL_IS_NULL_LEN; |
2778 | break; |
2779 | case Item_func::ISNOTNULL_FUNC: |
2780 | last_str = SPIDER_SQL_IS_NOT_NULL_STR; |
2781 | last_str_length = SPIDER_SQL_IS_NOT_NULL_LEN; |
2782 | break; |
2783 | case Item_func::UNKNOWN_FUNC: |
2784 | func_name = (char*) item_func->func_name(); |
2785 | func_name_length = strlen(func_name); |
2786 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
2787 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
2788 | if (func_name_length == 1 && |
2789 | ( |
2790 | !strncasecmp("+" , func_name, func_name_length) || |
2791 | !strncasecmp("-" , func_name, func_name_length) || |
2792 | !strncasecmp("*" , func_name, func_name_length) || |
2793 | !strncasecmp("/" , func_name, func_name_length) || |
2794 | !strncasecmp("%" , func_name, func_name_length) || |
2795 | !strncasecmp("&" , func_name, func_name_length) || |
2796 | !strncasecmp("|" , func_name, func_name_length) || |
2797 | !strncasecmp("^" , func_name, func_name_length) |
2798 | ) |
2799 | ) { |
2800 | /* no action */ |
2801 | break; |
2802 | } else if (func_name_length == 2 && |
2803 | ( |
2804 | !strncasecmp("<<" , func_name, func_name_length) || |
2805 | !strncasecmp(">>" , func_name, func_name_length) |
2806 | ) |
2807 | ) { |
2808 | /* no action */ |
2809 | break; |
2810 | } else if (func_name_length == 3 && |
2811 | !strncasecmp("div" , func_name, func_name_length) |
2812 | ) { |
2813 | /* no action */ |
2814 | break; |
2815 | } else if (func_name_length == 4) |
2816 | { |
2817 | if ( |
2818 | !strncasecmp("rand" , func_name, func_name_length) && |
2819 | #ifdef SPIDER_Item_args_arg_count_IS_PROTECTED |
2820 | !item_func->argument_count() |
2821 | #else |
2822 | !item_func->arg_count |
2823 | #endif |
2824 | ) { |
2825 | if (str) |
2826 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
2827 | DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, |
2828 | alias, alias_length, dbton_id, use_fields, fields)); |
2829 | } else if ( |
2830 | !strncasecmp("case" , func_name, func_name_length) |
2831 | ) { |
2832 | #ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC |
2833 | Item_func_case *item_func_case = (Item_func_case *) item_func; |
2834 | if (str) |
2835 | { |
2836 | if (str->reserve(SPIDER_SQL_CASE_LEN)) |
2837 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2838 | str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); |
2839 | } |
2840 | if (item_func_case->first_expr_num != -1) |
2841 | { |
2842 | if ((error_num = spider_db_print_item_type( |
2843 | item_list[item_func_case->first_expr_num], spider, str, |
2844 | alias, alias_length, dbton_id, use_fields, fields))) |
2845 | DBUG_RETURN(error_num); |
2846 | } |
2847 | for (roop_count = 0; roop_count < item_func_case->ncases; |
2848 | roop_count += 2) |
2849 | { |
2850 | if (str) |
2851 | { |
2852 | if (str->reserve(SPIDER_SQL_WHEN_LEN)) |
2853 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2854 | str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); |
2855 | } |
2856 | if ((error_num = spider_db_print_item_type( |
2857 | item_list[roop_count], spider, str, |
2858 | alias, alias_length, dbton_id, use_fields, fields))) |
2859 | DBUG_RETURN(error_num); |
2860 | if (str) |
2861 | { |
2862 | if (str->reserve(SPIDER_SQL_THEN_LEN)) |
2863 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2864 | str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); |
2865 | } |
2866 | if ((error_num = spider_db_print_item_type( |
2867 | item_list[roop_count + 1], spider, str, |
2868 | alias, alias_length, dbton_id, use_fields, fields))) |
2869 | DBUG_RETURN(error_num); |
2870 | } |
2871 | if (item_func_case->else_expr_num != -1) |
2872 | { |
2873 | if (str) |
2874 | { |
2875 | if (str->reserve(SPIDER_SQL_ELSE_LEN)) |
2876 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2877 | str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); |
2878 | } |
2879 | if ((error_num = spider_db_print_item_type( |
2880 | item_list[item_func_case->else_expr_num], spider, str, |
2881 | alias, alias_length, dbton_id, use_fields, fields))) |
2882 | DBUG_RETURN(error_num); |
2883 | } |
2884 | if (str) |
2885 | { |
2886 | if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) |
2887 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2888 | str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); |
2889 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
2890 | SPIDER_SQL_CLOSE_PAREN_LEN); |
2891 | } |
2892 | DBUG_RETURN(0); |
2893 | #else |
2894 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
2895 | #endif |
2896 | } |
2897 | } else if (func_name_length == 6 && |
2898 | !strncasecmp("istrue" , func_name, func_name_length) |
2899 | ) { |
2900 | last_str = SPIDER_SQL_IS_TRUE_STR; |
2901 | last_str_length = SPIDER_SQL_IS_TRUE_LEN; |
2902 | break; |
2903 | } else if (func_name_length == 7) |
2904 | { |
2905 | if (!strncasecmp("isfalse" , func_name, func_name_length)) |
2906 | { |
2907 | last_str = SPIDER_SQL_IS_FALSE_STR; |
2908 | last_str_length = SPIDER_SQL_IS_FALSE_LEN; |
2909 | break; |
2910 | } else if ( |
2911 | !strncasecmp("sysdate" , func_name, func_name_length) || |
2912 | !strncasecmp("curdate" , func_name, func_name_length) || |
2913 | !strncasecmp("curtime" , func_name, func_name_length) |
2914 | ) { |
2915 | if (str) |
2916 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
2917 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
2918 | alias, alias_length, dbton_id, use_fields, fields)); |
2919 | } else if ( |
2920 | !strncasecmp("convert" , func_name, func_name_length) |
2921 | ) { |
2922 | if (str) |
2923 | { |
2924 | if (str->reserve(func_name_length * 2 + SPIDER_SQL_OPEN_PAREN_LEN)) |
2925 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2926 | str->q_append(func_name, func_name_length); |
2927 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, |
2928 | SPIDER_SQL_OPEN_PAREN_LEN); |
2929 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
2930 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
2931 | } |
2932 | break; |
2933 | } |
2934 | } else if (func_name_length == 8 && |
2935 | ( |
2936 | !strncasecmp("utc_date" , func_name, func_name_length) || |
2937 | !strncasecmp("utc_time" , func_name, func_name_length) |
2938 | ) |
2939 | ) { |
2940 | if (str) |
2941 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
2942 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
2943 | alias, alias_length, dbton_id, use_fields, fields)); |
2944 | } else if (func_name_length == 9 && |
2945 | !strncasecmp("isnottrue" , func_name, func_name_length) |
2946 | ) { |
2947 | last_str = SPIDER_SQL_IS_NOT_TRUE_STR; |
2948 | last_str_length = SPIDER_SQL_IS_NOT_TRUE_LEN; |
2949 | break; |
2950 | } else if (func_name_length == 10) |
2951 | { |
2952 | if (!strncasecmp("isnotfalse" , func_name, func_name_length)) |
2953 | { |
2954 | last_str = SPIDER_SQL_IS_NOT_FALSE_STR; |
2955 | last_str_length = SPIDER_SQL_IS_NOT_FALSE_LEN; |
2956 | break; |
2957 | } else if (!strncasecmp("column_get" , func_name, func_name_length)) |
2958 | { |
2959 | if (str) |
2960 | { |
2961 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
2962 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
2963 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
2964 | str->q_append(func_name, func_name_length); |
2965 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
2966 | } |
2967 | func_name = SPIDER_SQL_COMMA_STR; |
2968 | func_name_length = SPIDER_SQL_COMMA_LEN; |
2969 | separete_str = SPIDER_SQL_COMMA_STR; |
2970 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
2971 | break; |
2972 | } |
2973 | } else if (func_name_length == 12) |
2974 | { |
2975 | if (!strncasecmp("cast_as_date" , func_name, func_name_length)) |
2976 | { |
2977 | item = item_list[0]; |
2978 | if (item->type() == Item::FUNC_ITEM) |
2979 | { |
2980 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
2981 | Item_func *ifunc = (Item_func *) item; |
2982 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
2983 | { |
2984 | const char *child_func_name; |
2985 | int child_func_name_length; |
2986 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
2987 | child_func_name = (char*) ifunc->func_name(); |
2988 | child_func_name_length = strlen(child_func_name); |
2989 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
2990 | if ( |
2991 | child_func_name_length == 10 && |
2992 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
2993 | ) { |
2994 | DBUG_PRINT("info" ,("spider this is merge func" )); |
2995 | merge_func = TRUE; |
2996 | } |
2997 | } |
2998 | } |
2999 | |
3000 | if (str) |
3001 | { |
3002 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3003 | if (!merge_func) |
3004 | { |
3005 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3006 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3007 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3008 | } |
3009 | } |
3010 | last_str = SPIDER_SQL_AS_DATE_STR; |
3011 | last_str_length = SPIDER_SQL_AS_DATE_LEN; |
3012 | break; |
3013 | } else if (!strncasecmp("cast_as_time" , func_name, func_name_length)) |
3014 | { |
3015 | item = item_list[0]; |
3016 | if (item->type() == Item::FUNC_ITEM) |
3017 | { |
3018 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3019 | Item_func *ifunc = (Item_func *) item; |
3020 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3021 | { |
3022 | const char *child_func_name; |
3023 | int child_func_name_length; |
3024 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3025 | child_func_name = (char*) ifunc->func_name(); |
3026 | child_func_name_length = strlen(child_func_name); |
3027 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3028 | if ( |
3029 | child_func_name_length == 10 && |
3030 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3031 | ) { |
3032 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3033 | merge_func = TRUE; |
3034 | } |
3035 | } |
3036 | } |
3037 | |
3038 | if (str) |
3039 | { |
3040 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3041 | if (!merge_func) |
3042 | { |
3043 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3044 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3045 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3046 | } |
3047 | } |
3048 | last_str = SPIDER_SQL_AS_TIME_STR; |
3049 | last_str_length = SPIDER_SQL_AS_TIME_LEN; |
3050 | break; |
3051 | } |
3052 | } else if (func_name_length == 13) |
3053 | { |
3054 | if (!strncasecmp("utc_timestamp" , func_name, func_name_length)) |
3055 | { |
3056 | if (str) |
3057 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3058 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3059 | alias, alias_length, dbton_id, use_fields, fields)); |
3060 | } else if (!strncasecmp("timestampdiff" , func_name, func_name_length)) |
3061 | { |
3062 | #ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC |
3063 | Item_func_timestamp_diff *item_func_timestamp_diff = |
3064 | (Item_func_timestamp_diff *) item_func; |
3065 | if (str) |
3066 | { |
3067 | const char *interval_str; |
3068 | uint interval_len; |
3069 | switch (item_func_timestamp_diff->int_type) |
3070 | { |
3071 | case INTERVAL_YEAR: |
3072 | interval_str = SPIDER_SQL_YEAR_STR; |
3073 | interval_len = SPIDER_SQL_YEAR_LEN; |
3074 | break; |
3075 | case INTERVAL_QUARTER: |
3076 | interval_str = SPIDER_SQL_QUARTER_STR; |
3077 | interval_len = SPIDER_SQL_QUARTER_LEN; |
3078 | break; |
3079 | case INTERVAL_MONTH: |
3080 | interval_str = SPIDER_SQL_MONTH_STR; |
3081 | interval_len = SPIDER_SQL_MONTH_LEN; |
3082 | break; |
3083 | case INTERVAL_WEEK: |
3084 | interval_str = SPIDER_SQL_WEEK_STR; |
3085 | interval_len = SPIDER_SQL_WEEK_LEN; |
3086 | break; |
3087 | case INTERVAL_DAY: |
3088 | interval_str = SPIDER_SQL_DAY_STR; |
3089 | interval_len = SPIDER_SQL_DAY_LEN; |
3090 | break; |
3091 | case INTERVAL_HOUR: |
3092 | interval_str = SPIDER_SQL_HOUR_STR; |
3093 | interval_len = SPIDER_SQL_HOUR_LEN; |
3094 | break; |
3095 | case INTERVAL_MINUTE: |
3096 | interval_str = SPIDER_SQL_MINUTE_STR; |
3097 | interval_len = SPIDER_SQL_MINUTE_LEN; |
3098 | break; |
3099 | case INTERVAL_SECOND: |
3100 | interval_str = SPIDER_SQL_SECOND_STR; |
3101 | interval_len = SPIDER_SQL_SECOND_LEN; |
3102 | break; |
3103 | case INTERVAL_MICROSECOND: |
3104 | interval_str = SPIDER_SQL_MICROSECOND_STR; |
3105 | interval_len = SPIDER_SQL_MICROSECOND_LEN; |
3106 | break; |
3107 | default: |
3108 | interval_str = "" ; |
3109 | interval_len = 0; |
3110 | break; |
3111 | } |
3112 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3113 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN + |
3114 | interval_len + SPIDER_SQL_COMMA_LEN)) |
3115 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3116 | str->q_append(func_name, func_name_length); |
3117 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3118 | str->q_append(interval_str, interval_len); |
3119 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3120 | } |
3121 | if ((error_num = spider_db_print_item_type(item_list[0], spider, |
3122 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3123 | DBUG_RETURN(error_num); |
3124 | if (str) |
3125 | { |
3126 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
3127 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3128 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3129 | } |
3130 | if ((error_num = spider_db_print_item_type(item_list[1], spider, |
3131 | str, alias, alias_length, dbton_id, use_fields, fields))) |
3132 | DBUG_RETURN(error_num); |
3133 | if (str) |
3134 | { |
3135 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
3136 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3137 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3138 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3139 | } |
3140 | DBUG_RETURN(0); |
3141 | #else |
3142 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3143 | #endif |
3144 | } |
3145 | } else if (func_name_length == 14) |
3146 | { |
3147 | if (!strncasecmp("cast_as_binary" , func_name, func_name_length)) |
3148 | { |
3149 | item = item_list[0]; |
3150 | if (item->type() == Item::FUNC_ITEM) |
3151 | { |
3152 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3153 | Item_func *ifunc = (Item_func *) item; |
3154 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3155 | { |
3156 | const char *child_func_name; |
3157 | int child_func_name_length; |
3158 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3159 | child_func_name = (char*) ifunc->func_name(); |
3160 | child_func_name_length = strlen(child_func_name); |
3161 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3162 | if ( |
3163 | child_func_name_length == 10 && |
3164 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3165 | ) { |
3166 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3167 | merge_func = TRUE; |
3168 | } |
3169 | } |
3170 | } |
3171 | |
3172 | if (str) |
3173 | { |
3174 | char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; |
3175 | spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); |
3176 | tmp_str.init_calc_mem(123); |
3177 | tmp_str.length(0); |
3178 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3179 | if (!merge_func) |
3180 | { |
3181 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3182 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3183 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3184 | } |
3185 | #if MYSQL_VERSION_ID < 50500 |
3186 | item_func->print(tmp_str.get_str(), QT_IS); |
3187 | #else |
3188 | item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); |
3189 | #endif |
3190 | tmp_str.mem_calc(); |
3191 | if (tmp_str.reserve(1)) |
3192 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3193 | tmp_ptr = tmp_str.c_ptr_quick(); |
3194 | DBUG_PRINT("info" ,("spider tmp_ptr = %s" , tmp_ptr)); |
3195 | while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_BINARY_STR))) |
3196 | tmp_ptr = tmp_ptr2 + 1; |
3197 | last_str = tmp_ptr - 1; |
3198 | last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; |
3199 | } |
3200 | break; |
3201 | } else if (!strncasecmp("cast_as_signed" , func_name, func_name_length)) |
3202 | { |
3203 | item = item_list[0]; |
3204 | if (item->type() == Item::FUNC_ITEM) |
3205 | { |
3206 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3207 | Item_func *ifunc = (Item_func *) item; |
3208 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3209 | { |
3210 | const char *child_func_name; |
3211 | int child_func_name_length; |
3212 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3213 | child_func_name = (char*) ifunc->func_name(); |
3214 | child_func_name_length = strlen(child_func_name); |
3215 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3216 | if ( |
3217 | child_func_name_length == 10 && |
3218 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3219 | ) { |
3220 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3221 | merge_func = TRUE; |
3222 | } |
3223 | } |
3224 | } |
3225 | |
3226 | if (str) |
3227 | { |
3228 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3229 | if (!merge_func) |
3230 | { |
3231 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3232 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3233 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3234 | } |
3235 | } |
3236 | last_str = SPIDER_SQL_AS_SIGNED_STR; |
3237 | last_str_length = SPIDER_SQL_AS_SIGNED_LEN; |
3238 | break; |
3239 | } |
3240 | } else if (func_name_length == 16) |
3241 | { |
3242 | if (!strncasecmp("cast_as_unsigned" , func_name, func_name_length)) |
3243 | { |
3244 | item = item_list[0]; |
3245 | if (item->type() == Item::FUNC_ITEM) |
3246 | { |
3247 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3248 | Item_func *ifunc = (Item_func *) item; |
3249 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3250 | { |
3251 | const char *child_func_name; |
3252 | int child_func_name_length; |
3253 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3254 | child_func_name = (char*) ifunc->func_name(); |
3255 | child_func_name_length = strlen(child_func_name); |
3256 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3257 | if ( |
3258 | child_func_name_length == 10 && |
3259 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3260 | ) { |
3261 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3262 | merge_func = TRUE; |
3263 | } |
3264 | } |
3265 | } |
3266 | |
3267 | if (str) |
3268 | { |
3269 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3270 | if (!merge_func) |
3271 | { |
3272 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3273 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3274 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3275 | } |
3276 | } |
3277 | last_str = SPIDER_SQL_AS_UNSIGNED_STR; |
3278 | last_str_length = SPIDER_SQL_AS_UNSIGNED_LEN; |
3279 | break; |
3280 | } else if (!strncasecmp("decimal_typecast" , func_name, |
3281 | func_name_length)) |
3282 | { |
3283 | item = item_list[0]; |
3284 | if (item->type() == Item::FUNC_ITEM) |
3285 | { |
3286 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3287 | Item_func *ifunc = (Item_func *) item; |
3288 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3289 | { |
3290 | const char *child_func_name; |
3291 | int child_func_name_length; |
3292 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3293 | child_func_name = (char*) ifunc->func_name(); |
3294 | child_func_name_length = strlen(child_func_name); |
3295 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3296 | if ( |
3297 | child_func_name_length == 10 && |
3298 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3299 | ) { |
3300 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3301 | merge_func = TRUE; |
3302 | } |
3303 | } |
3304 | } |
3305 | |
3306 | if (str) |
3307 | { |
3308 | char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; |
3309 | spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); |
3310 | tmp_str.init_calc_mem(124); |
3311 | tmp_str.length(0); |
3312 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3313 | if (!merge_func) |
3314 | { |
3315 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3316 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3317 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3318 | } |
3319 | #if MYSQL_VERSION_ID < 50500 |
3320 | item_func->print(tmp_str.get_str(), QT_IS); |
3321 | #else |
3322 | item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); |
3323 | #endif |
3324 | tmp_str.mem_calc(); |
3325 | if (tmp_str.reserve(1)) |
3326 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3327 | tmp_ptr = tmp_str.c_ptr_quick(); |
3328 | DBUG_PRINT("info" ,("spider tmp_ptr = %s" , tmp_ptr)); |
3329 | while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_DECIMAL_STR))) |
3330 | tmp_ptr = tmp_ptr2 + 1; |
3331 | last_str = tmp_ptr - 1; |
3332 | last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; |
3333 | } |
3334 | break; |
3335 | } else if (!strncasecmp("cast_as_datetime" , func_name, |
3336 | func_name_length)) |
3337 | { |
3338 | item = item_list[0]; |
3339 | if (item->type() == Item::FUNC_ITEM) |
3340 | { |
3341 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3342 | Item_func *ifunc = (Item_func *) item; |
3343 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3344 | { |
3345 | const char *child_func_name; |
3346 | int child_func_name_length; |
3347 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3348 | child_func_name = (char*) ifunc->func_name(); |
3349 | child_func_name_length = strlen(child_func_name); |
3350 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3351 | if ( |
3352 | child_func_name_length == 10 && |
3353 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3354 | ) { |
3355 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3356 | merge_func = TRUE; |
3357 | } |
3358 | } |
3359 | } |
3360 | |
3361 | if (str) |
3362 | { |
3363 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3364 | if (!merge_func) |
3365 | { |
3366 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3367 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3368 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3369 | } |
3370 | } |
3371 | last_str = SPIDER_SQL_AS_DATETIME_STR; |
3372 | last_str_length = SPIDER_SQL_AS_DATETIME_LEN; |
3373 | break; |
3374 | } |
3375 | } else if (func_name_length == 17) |
3376 | { |
3377 | if (!strncasecmp("date_add_interval" , func_name, func_name_length)) |
3378 | { |
3379 | Item_date_add_interval *item_date_add_interval = |
3380 | (Item_date_add_interval *) item_func; |
3381 | func_name = spider_db_timefunc_interval_str[ |
3382 | item_date_add_interval->int_type]; |
3383 | func_name_length = strlen(func_name); |
3384 | if ((error_num = spider_db_print_item_type(item_list[0], spider, str, |
3385 | alias, alias_length, dbton_id, use_fields, fields))) |
3386 | DBUG_RETURN(error_num); |
3387 | if (str) |
3388 | { |
3389 | if (item_date_add_interval->date_sub_interval) |
3390 | { |
3391 | if (str->reserve(SPIDER_SQL_NEGINTERVAL_LEN)) |
3392 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3393 | str->q_append(SPIDER_SQL_NEGINTERVAL_STR, |
3394 | SPIDER_SQL_NEGINTERVAL_LEN); |
3395 | } else { |
3396 | if (str->reserve(SPIDER_SQL_INTERVAL_LEN)) |
3397 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3398 | str->q_append(SPIDER_SQL_INTERVAL_STR, SPIDER_SQL_INTERVAL_LEN); |
3399 | } |
3400 | } |
3401 | if ((error_num = spider_db_print_item_type(item_list[1], spider, str, |
3402 | alias, alias_length, dbton_id, use_fields, fields))) |
3403 | DBUG_RETURN(error_num); |
3404 | if (str) |
3405 | { |
3406 | if (str->reserve(func_name_length + SPIDER_SQL_CLOSE_PAREN_LEN)) |
3407 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3408 | str->q_append(func_name, func_name_length); |
3409 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3410 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3411 | } |
3412 | DBUG_RETURN(0); |
3413 | } |
3414 | } |
3415 | if (str) |
3416 | { |
3417 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3418 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3419 | str->q_append(func_name, func_name_length); |
3420 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3421 | } |
3422 | func_name = SPIDER_SQL_COMMA_STR; |
3423 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3424 | separete_str = SPIDER_SQL_COMMA_STR; |
3425 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3426 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3427 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3428 | break; |
3429 | case Item_func::NOW_FUNC: |
3430 | if (str) |
3431 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3432 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3433 | alias, alias_length, dbton_id, use_fields, fields)); |
3434 | case Item_func::CHAR_TYPECAST_FUNC: |
3435 | DBUG_PRINT("info" ,("spider CHAR_TYPECAST_FUNC" )); |
3436 | { |
3437 | item = item_list[0]; |
3438 | if (item->type() == Item::FUNC_ITEM) |
3439 | { |
3440 | DBUG_PRINT("info" ,("spider child is FUNC_ITEM" )); |
3441 | Item_func *ifunc = (Item_func *) item; |
3442 | if (ifunc->functype() == Item_func::UNKNOWN_FUNC) |
3443 | { |
3444 | const char *child_func_name; |
3445 | int child_func_name_length; |
3446 | DBUG_PRINT("info" ,("spider child is UNKNOWN_FUNC" )); |
3447 | child_func_name = (char*) ifunc->func_name(); |
3448 | child_func_name_length = strlen(child_func_name); |
3449 | DBUG_PRINT("info" ,("spider child func_name is %s" , child_func_name)); |
3450 | if ( |
3451 | child_func_name_length == 10 && |
3452 | !strncasecmp("column_get" , child_func_name, child_func_name_length) |
3453 | ) { |
3454 | DBUG_PRINT("info" ,("spider this is merge func" )); |
3455 | merge_func = TRUE; |
3456 | } |
3457 | } |
3458 | } |
3459 | |
3460 | if (str) |
3461 | { |
3462 | char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; |
3463 | spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); |
3464 | tmp_str.init_calc_mem(125); |
3465 | tmp_str.length(0); |
3466 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3467 | if (!merge_func) |
3468 | { |
3469 | if (str->reserve(SPIDER_SQL_CAST_LEN)) |
3470 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3471 | str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); |
3472 | } |
3473 | #if MYSQL_VERSION_ID < 50500 |
3474 | item_func->print(tmp_str.get_str(), QT_IS); |
3475 | #else |
3476 | item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); |
3477 | #endif |
3478 | tmp_str.mem_calc(); |
3479 | if (tmp_str.reserve(1)) |
3480 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3481 | tmp_ptr = tmp_str.c_ptr_quick(); |
3482 | DBUG_PRINT("info" ,("spider tmp_ptr = %s" , tmp_ptr)); |
3483 | while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_CHAR_STR))) |
3484 | tmp_ptr = tmp_ptr2 + 1; |
3485 | last_str = tmp_ptr - 1; |
3486 | last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; |
3487 | } |
3488 | } |
3489 | break; |
3490 | case Item_func::NOT_FUNC: |
3491 | DBUG_PRINT("info" ,("spider NOT_FUNC" )); |
3492 | if (item_list[0]->type() == Item::COND_ITEM) |
3493 | { |
3494 | DBUG_PRINT("info" ,("spider item_list[0] is COND_ITEM" )); |
3495 | Item_cond *item_cond = (Item_cond *) item_list[0]; |
3496 | if (item_cond->functype() == Item_func::COND_AND_FUNC) |
3497 | { |
3498 | DBUG_PRINT("info" ,("spider item_cond is COND_AND_FUNC" )); |
3499 | List_iterator_fast<Item> lif(*(item_cond->argument_list())); |
3500 | bool has_expr_cache_item = FALSE; |
3501 | bool has_isnotnull_func = FALSE; |
3502 | bool has_other_item = FALSE; |
3503 | while((item = lif++)) |
3504 | { |
3505 | #ifdef SPIDER_HAS_EXPR_CACHE_ITEM |
3506 | if ( |
3507 | item->type() == Item::EXPR_CACHE_ITEM |
3508 | ) { |
3509 | DBUG_PRINT("info" ,("spider EXPR_CACHE_ITEM" )); |
3510 | has_expr_cache_item = TRUE; |
3511 | } else |
3512 | #endif |
3513 | if ( |
3514 | item->type() == Item::FUNC_ITEM && |
3515 | ((Item_func *) item)->functype() == Item_func::ISNOTNULL_FUNC |
3516 | ) { |
3517 | DBUG_PRINT("info" ,("spider ISNOTNULL_FUNC" )); |
3518 | has_isnotnull_func = TRUE; |
3519 | } else { |
3520 | DBUG_PRINT("info" ,("spider has other item" )); |
3521 | DBUG_PRINT("info" ,("spider COND type=%d" , item->type())); |
3522 | has_other_item = TRUE; |
3523 | } |
3524 | } |
3525 | if (has_expr_cache_item && has_isnotnull_func && !has_other_item) |
3526 | { |
3527 | DBUG_PRINT("info" ,("spider NOT EXISTS skip" )); |
3528 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3529 | } |
3530 | } |
3531 | } |
3532 | if (str) |
3533 | { |
3534 | func_name = (char*) item_func->func_name(); |
3535 | func_name_length = strlen(func_name); |
3536 | if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) |
3537 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3538 | str->q_append(func_name, func_name_length); |
3539 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
3540 | } |
3541 | break; |
3542 | case Item_func::NEG_FUNC: |
3543 | if (str) |
3544 | { |
3545 | func_name = (char*) item_func->func_name(); |
3546 | func_name_length = strlen(func_name); |
3547 | if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) |
3548 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3549 | str->q_append(func_name, func_name_length); |
3550 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
3551 | } |
3552 | break; |
3553 | case Item_func::IN_FUNC: |
3554 | if (((Item_func_opt_neg *) item_func)->negated) |
3555 | { |
3556 | func_name = SPIDER_SQL_NOT_IN_STR; |
3557 | func_name_length = SPIDER_SQL_NOT_IN_LEN; |
3558 | separete_str = SPIDER_SQL_COMMA_STR; |
3559 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3560 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3561 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3562 | } else { |
3563 | func_name = SPIDER_SQL_IN_STR; |
3564 | func_name_length = SPIDER_SQL_IN_LEN; |
3565 | separete_str = SPIDER_SQL_COMMA_STR; |
3566 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3567 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3568 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3569 | } |
3570 | break; |
3571 | case Item_func::BETWEEN: |
3572 | if (((Item_func_opt_neg *) item_func)->negated) |
3573 | { |
3574 | func_name = SPIDER_SQL_NOT_BETWEEN_STR; |
3575 | func_name_length = SPIDER_SQL_NOT_BETWEEN_LEN; |
3576 | separete_str = SPIDER_SQL_AND_STR; |
3577 | separete_str_length = SPIDER_SQL_AND_LEN; |
3578 | } else { |
3579 | func_name = (char*) item_func->func_name(); |
3580 | func_name_length = strlen(func_name); |
3581 | separete_str = SPIDER_SQL_AND_STR; |
3582 | separete_str_length = SPIDER_SQL_AND_LEN; |
3583 | } |
3584 | break; |
3585 | case Item_func::UDF_FUNC: |
3586 | use_pushdown_udf = spider_param_use_pushdown_udf(spider->trx->thd, |
3587 | spider->share->use_pushdown_udf); |
3588 | if (!use_pushdown_udf) |
3589 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3590 | if (str) |
3591 | { |
3592 | func_name = (char*) item_func->func_name(); |
3593 | func_name_length = strlen(func_name); |
3594 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3595 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3596 | if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3597 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3598 | str->q_append(func_name, func_name_length); |
3599 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3600 | } |
3601 | func_name = SPIDER_SQL_COMMA_STR; |
3602 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3603 | separete_str = SPIDER_SQL_COMMA_STR; |
3604 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3605 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3606 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3607 | break; |
3608 | #ifdef MARIADB_BASE_VERSION |
3609 | case Item_func::XOR_FUNC: |
3610 | #else |
3611 | case Item_func::COND_XOR_FUNC: |
3612 | #endif |
3613 | if (str) |
3614 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3615 | DBUG_RETURN( |
3616 | spider_db_open_item_cond((Item_cond *) item_func, spider, str, |
3617 | alias, alias_length, dbton_id, use_fields, fields)); |
3618 | case Item_func::TRIG_COND_FUNC: |
3619 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3620 | case Item_func::GUSERVAR_FUNC: |
3621 | if (str) |
3622 | str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); |
3623 | if (item_func->result_type() == STRING_RESULT) |
3624 | DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, |
3625 | alias, alias_length, dbton_id, use_fields, fields)); |
3626 | else |
3627 | DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, |
3628 | alias, alias_length, dbton_id, use_fields, fields)); |
3629 | case Item_func::FT_FUNC: |
3630 | if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) |
3631 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3632 | start_item = 1; |
3633 | if (str) |
3634 | { |
3635 | if (str->reserve(SPIDER_SQL_MATCH_LEN)) |
3636 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3637 | str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); |
3638 | } |
3639 | separete_str = SPIDER_SQL_COMMA_STR; |
3640 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3641 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3642 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3643 | break; |
3644 | case Item_func::SP_EQUALS_FUNC: |
3645 | if (str) |
3646 | { |
3647 | func_name = SPIDER_SQL_MBR_EQUAL_STR; |
3648 | func_name_length = SPIDER_SQL_MBR_EQUAL_LEN; |
3649 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3650 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3651 | if (str->reserve(func_name_length)) |
3652 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3653 | str->q_append(func_name, func_name_length); |
3654 | } |
3655 | func_name = SPIDER_SQL_COMMA_STR; |
3656 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3657 | separete_str = SPIDER_SQL_COMMA_STR; |
3658 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3659 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3660 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3661 | break; |
3662 | case Item_func::SP_DISJOINT_FUNC: |
3663 | case Item_func::SP_INTERSECTS_FUNC: |
3664 | case Item_func::SP_TOUCHES_FUNC: |
3665 | case Item_func::SP_CROSSES_FUNC: |
3666 | case Item_func::SP_WITHIN_FUNC: |
3667 | case Item_func::SP_CONTAINS_FUNC: |
3668 | case Item_func::SP_OVERLAPS_FUNC: |
3669 | if (str) |
3670 | { |
3671 | func_name = (char*) item_func->func_name(); |
3672 | func_name_length = strlen(func_name); |
3673 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3674 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3675 | if (str->reserve( |
3676 | #ifndef SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR |
3677 | SPIDER_SQL_MBR_LEN + |
3678 | #endif |
3679 | func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) |
3680 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3681 | #ifndef SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR |
3682 | str->q_append(SPIDER_SQL_MBR_STR, SPIDER_SQL_MBR_LEN); |
3683 | #endif |
3684 | str->q_append(func_name, func_name_length); |
3685 | str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
3686 | } |
3687 | func_name = SPIDER_SQL_COMMA_STR; |
3688 | func_name_length = SPIDER_SQL_COMMA_LEN; |
3689 | separete_str = SPIDER_SQL_COMMA_STR; |
3690 | separete_str_length = SPIDER_SQL_COMMA_LEN; |
3691 | last_str = SPIDER_SQL_CLOSE_PAREN_STR; |
3692 | last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; |
3693 | break; |
3694 | case Item_func::EQ_FUNC: |
3695 | case Item_func::EQUAL_FUNC: |
3696 | case Item_func::NE_FUNC: |
3697 | case Item_func::LT_FUNC: |
3698 | case Item_func::LE_FUNC: |
3699 | case Item_func::GE_FUNC: |
3700 | case Item_func::GT_FUNC: |
3701 | case Item_func::LIKE_FUNC: |
3702 | if (str) |
3703 | { |
3704 | func_name = (char*) item_func->func_name(); |
3705 | func_name_length = strlen(func_name); |
3706 | } |
3707 | break; |
3708 | default: |
3709 | THD *thd = spider->trx->thd; |
3710 | SPIDER_SHARE *share = spider->share; |
3711 | if (spider_param_skip_default_condition(thd, |
3712 | share->skip_default_condition)) |
3713 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3714 | if (str) |
3715 | { |
3716 | func_name = (char*) item_func->func_name(); |
3717 | func_name_length = strlen(func_name); |
3718 | } |
3719 | break; |
3720 | } |
3721 | DBUG_PRINT("info" ,("spider func_name = %s" , func_name)); |
3722 | DBUG_PRINT("info" ,("spider func_name_length = %d" , func_name_length)); |
3723 | DBUG_PRINT("info" ,("spider separete_str = %s" , separete_str)); |
3724 | DBUG_PRINT("info" ,("spider separete_str_length = %d" , separete_str_length)); |
3725 | DBUG_PRINT("info" ,("spider last_str = %s" , last_str)); |
3726 | DBUG_PRINT("info" ,("spider last_str_length = %d" , last_str_length)); |
3727 | if (item_count) |
3728 | { |
3729 | item_count--; |
3730 | for (roop_count = start_item; roop_count < item_count; roop_count++) |
3731 | { |
3732 | item = item_list[roop_count]; |
3733 | if ((error_num = spider_db_print_item_type(item, spider, str, |
3734 | alias, alias_length, dbton_id, use_fields, fields))) |
3735 | DBUG_RETURN(error_num); |
3736 | if (roop_count == 1) |
3737 | { |
3738 | func_name = separete_str; |
3739 | func_name_length = separete_str_length; |
3740 | } |
3741 | if (str) |
3742 | { |
3743 | if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN * 2)) |
3744 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3745 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
3746 | str->q_append(func_name, func_name_length); |
3747 | str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); |
3748 | } |
3749 | } |
3750 | item = item_list[roop_count]; |
3751 | if ((error_num = spider_db_print_item_type(item, spider, str, |
3752 | alias, alias_length, dbton_id, use_fields, fields))) |
3753 | DBUG_RETURN(error_num); |
3754 | } |
3755 | if (item_func->functype() == Item_func::FT_FUNC) |
3756 | { |
3757 | Item_func_match *item_func_match = (Item_func_match *)item_func; |
3758 | if (str) |
3759 | { |
3760 | if (str->reserve(SPIDER_SQL_AGAINST_LEN)) |
3761 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3762 | str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); |
3763 | } |
3764 | item = item_list[0]; |
3765 | if ((error_num = spider_db_print_item_type(item, spider, str, |
3766 | alias, alias_length, dbton_id, use_fields, fields))) |
3767 | DBUG_RETURN(error_num); |
3768 | if (str) |
3769 | { |
3770 | if (str->reserve( |
3771 | ((item_func_match->flags & FT_BOOL) ? |
3772 | SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + |
3773 | ((item_func_match->flags & FT_EXPAND) ? |
3774 | SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) |
3775 | )) |
3776 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3777 | if (item_func_match->flags & FT_BOOL) |
3778 | str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, |
3779 | SPIDER_SQL_IN_BOOLEAN_MODE_LEN); |
3780 | if (item_func_match->flags & FT_EXPAND) |
3781 | str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, |
3782 | SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); |
3783 | } |
3784 | } else if (item_func->functype() == Item_func::UNKNOWN_FUNC) |
3785 | { |
3786 | if ( |
3787 | func_name_length == 7 && |
3788 | !strncasecmp("convert" , func_name, func_name_length) |
3789 | ) { |
3790 | if (str) |
3791 | { |
3792 | Item_func_conv_charset *item_func_conv_charset = |
3793 | (Item_func_conv_charset *)item_func; |
3794 | CHARSET_INFO *conv_charset = |
3795 | item_func_conv_charset->SPIDER_Item_func_conv_charset_conv_charset; |
3796 | uint cset_length = strlen(conv_charset->csname); |
3797 | if (str->reserve(SPIDER_SQL_USING_LEN + cset_length)) |
3798 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3799 | str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); |
3800 | str->q_append(conv_charset->csname, cset_length); |
3801 | } |
3802 | } |
3803 | } |
3804 | if (str) |
3805 | { |
3806 | if (merge_func) |
3807 | str->length(str->length() - SPIDER_SQL_CLOSE_PAREN_LEN); |
3808 | if (str->reserve(last_str_length + SPIDER_SQL_CLOSE_PAREN_LEN)) |
3809 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3810 | str->q_append(last_str, last_str_length); |
3811 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
3812 | } |
3813 | DBUG_RETURN(0); |
3814 | } |
3815 | |
3816 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
3817 | int spider_db_handlersocket_util::open_item_sum_func( |
3818 | Item_sum *item_sum, |
3819 | ha_spider *spider, |
3820 | spider_string *str, |
3821 | const char *alias, |
3822 | uint alias_length, |
3823 | bool use_fields, |
3824 | spider_fields *fields |
3825 | ) { |
3826 | uint dbton_id = spider_dbton_handlersocket.dbton_id; |
3827 | uint roop_count, item_count = item_sum->get_arg_count(); |
3828 | int error_num; |
3829 | DBUG_ENTER("spider_db_handlersocket_util::open_item_sum_func" ); |
3830 | DBUG_PRINT("info" ,("spider Sumfunctype = %d" , item_sum->sum_func())); |
3831 | switch (item_sum->sum_func()) |
3832 | { |
3833 | case Item_sum::COUNT_FUNC: |
3834 | case Item_sum::SUM_FUNC: |
3835 | case Item_sum::MIN_FUNC: |
3836 | case Item_sum::MAX_FUNC: |
3837 | { |
3838 | const char *func_name = item_sum->func_name(); |
3839 | uint func_name_length = strlen(func_name); |
3840 | Item *item, **args = item_sum->get_args(); |
3841 | if (str) |
3842 | { |
3843 | if (str->reserve(func_name_length)) |
3844 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3845 | str->q_append(func_name, func_name_length); |
3846 | } |
3847 | if (item_count) |
3848 | { |
3849 | item_count--; |
3850 | for (roop_count = 0; roop_count < item_count; roop_count++) |
3851 | { |
3852 | item = args[roop_count]; |
3853 | if ((error_num = spider_db_print_item_type(item, spider, str, |
3854 | alias, alias_length, dbton_id, use_fields, fields))) |
3855 | DBUG_RETURN(error_num); |
3856 | if (str) |
3857 | { |
3858 | if (str->reserve(SPIDER_SQL_COMMA_LEN)) |
3859 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3860 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
3861 | } |
3862 | } |
3863 | item = args[roop_count]; |
3864 | if ((error_num = spider_db_print_item_type(item, spider, str, |
3865 | alias, alias_length, dbton_id, use_fields, fields))) |
3866 | DBUG_RETURN(error_num); |
3867 | } |
3868 | if (str) |
3869 | { |
3870 | if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) |
3871 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3872 | str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, |
3873 | SPIDER_SQL_CLOSE_PAREN_LEN); |
3874 | } |
3875 | } |
3876 | break; |
3877 | case Item_sum::COUNT_DISTINCT_FUNC: |
3878 | case Item_sum::SUM_DISTINCT_FUNC: |
3879 | case Item_sum::AVG_FUNC: |
3880 | case Item_sum::AVG_DISTINCT_FUNC: |
3881 | case Item_sum::STD_FUNC: |
3882 | case Item_sum::VARIANCE_FUNC: |
3883 | case Item_sum::SUM_BIT_FUNC: |
3884 | case Item_sum::UDF_SUM_FUNC: |
3885 | case Item_sum::GROUP_CONCAT_FUNC: |
3886 | default: |
3887 | DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); |
3888 | } |
3889 | DBUG_RETURN(0); |
3890 | } |
3891 | #endif |
3892 | |
3893 | int spider_db_handlersocket_util::append_escaped_util( |
3894 | spider_string *to, |
3895 | String *from |
3896 | ) { |
3897 | DBUG_ENTER("spider_db_handlersocket_util::append_escaped_util" ); |
3898 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3899 | to->append_escape_string(from->ptr(), from->length()); |
3900 | DBUG_RETURN(0); |
3901 | } |
3902 | |
3903 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
3904 | int spider_db_handlersocket_util::append_from_and_tables( |
3905 | spider_fields *fields, |
3906 | spider_string *str |
3907 | ) { |
3908 | DBUG_ENTER("spider_db_handlersocket_util::append_from_and_tables" ); |
3909 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3910 | DBUG_ASSERT(0); |
3911 | DBUG_RETURN(0); |
3912 | } |
3913 | |
3914 | int spider_db_handlersocket_util::reappend_tables( |
3915 | spider_fields *fields, |
3916 | SPIDER_LINK_IDX_CHAIN *link_idx_chain, |
3917 | spider_string *str |
3918 | ) { |
3919 | DBUG_ENTER("spider_db_handlersocket_util::reappend_tables" ); |
3920 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3921 | DBUG_ASSERT(0); |
3922 | DBUG_RETURN(0); |
3923 | } |
3924 | |
3925 | int spider_db_handlersocket_util::append_where( |
3926 | spider_string *str |
3927 | ) { |
3928 | DBUG_ENTER("spider_db_handlersocket_util::append_where" ); |
3929 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3930 | DBUG_ASSERT(0); |
3931 | DBUG_RETURN(0); |
3932 | } |
3933 | |
3934 | int spider_db_handlersocket_util::append_having( |
3935 | spider_string *str |
3936 | ) { |
3937 | DBUG_ENTER("spider_db_handlersocket_util::append_having" ); |
3938 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3939 | DBUG_ASSERT(0); |
3940 | DBUG_RETURN(0); |
3941 | } |
3942 | #endif |
3943 | |
3944 | spider_handlersocket_share::spider_handlersocket_share( |
3945 | st_spider_share *share |
3946 | ) : spider_db_share( |
3947 | share |
3948 | ), |
3949 | table_names_str(NULL), |
3950 | db_names_str(NULL), |
3951 | db_table_str(NULL), |
3952 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
3953 | db_table_str_hash_value(NULL), |
3954 | #endif |
3955 | table_nm_max_length(0), |
3956 | db_nm_max_length(0), |
3957 | column_name_str(NULL), |
3958 | same_db_table_name(TRUE), |
3959 | first_all_link_idx(-1) |
3960 | { |
3961 | DBUG_ENTER("spider_handlersocket_share::spider_handlersocket_share" ); |
3962 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3963 | spider_alloc_calc_mem_init(mem_calc, 186); |
3964 | spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); |
3965 | DBUG_VOID_RETURN; |
3966 | } |
3967 | |
3968 | spider_handlersocket_share::~spider_handlersocket_share() |
3969 | { |
3970 | DBUG_ENTER("spider_handlersocket_share::~spider_handlersocket_share" ); |
3971 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3972 | free_column_name_str(); |
3973 | free_table_names_str(); |
3974 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
3975 | if (db_table_str_hash_value) |
3976 | { |
3977 | spider_free(spider_current_trx, db_table_str_hash_value, MYF(0)); |
3978 | } |
3979 | #endif |
3980 | spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); |
3981 | DBUG_VOID_RETURN; |
3982 | } |
3983 | |
3984 | int spider_handlersocket_share::init() |
3985 | { |
3986 | int error_num; |
3987 | DBUG_ENTER("spider_handlersocket_share::init" ); |
3988 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
3989 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
3990 | if (!(db_table_str_hash_value = (my_hash_value_type *) |
3991 | spider_bulk_alloc_mem(spider_current_trx, 203, |
3992 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
3993 | &db_table_str_hash_value, |
3994 | sizeof(my_hash_value_type) * spider_share->all_link_count, |
3995 | NullS)) |
3996 | ) { |
3997 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
3998 | } |
3999 | #endif |
4000 | |
4001 | if ( |
4002 | (error_num = create_table_names_str()) || |
4003 | ( |
4004 | spider_share->table_share && |
4005 | (error_num = create_column_name_str()) |
4006 | ) |
4007 | ) { |
4008 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4009 | } |
4010 | DBUG_RETURN(0); |
4011 | } |
4012 | |
4013 | int spider_handlersocket_share::append_table_name( |
4014 | spider_string *str, |
4015 | int all_link_idx |
4016 | ) { |
4017 | const char *db_nm = db_names_str[all_link_idx].ptr(); |
4018 | uint db_nm_len = db_names_str[all_link_idx].length(); |
4019 | const char *table_nm = table_names_str[all_link_idx].ptr(); |
4020 | uint table_nm_len = table_names_str[all_link_idx].length(); |
4021 | DBUG_ENTER("spider_handlersocket_share::append_table_name" ); |
4022 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4023 | if (str->reserve(db_nm_len + SPIDER_SQL_DOT_LEN + table_nm_len + |
4024 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) |
4025 | { |
4026 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4027 | } |
4028 | spider_db_handlersocket_utility.append_name(str, db_nm, db_nm_len); |
4029 | str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); |
4030 | spider_db_handlersocket_utility.append_name(str, table_nm, table_nm_len); |
4031 | DBUG_RETURN(0); |
4032 | } |
4033 | |
4034 | int spider_handlersocket_share::create_table_names_str() |
4035 | { |
4036 | int error_num, roop_count; |
4037 | uint table_nm_len, db_nm_len; |
4038 | spider_string *str, *first_tbl_nm_str, *first_db_nm_str, *first_db_tbl_str; |
4039 | char *first_tbl_nm, *first_db_nm; |
4040 | uint dbton_id = spider_dbton_handlersocket.dbton_id; |
4041 | DBUG_ENTER("spider_handlersocket_share::create_table_names_str" ); |
4042 | table_names_str = NULL; |
4043 | db_names_str = NULL; |
4044 | db_table_str = NULL; |
4045 | if ( |
4046 | !(table_names_str = new spider_string[spider_share->all_link_count]) || |
4047 | !(db_names_str = new spider_string[spider_share->all_link_count]) || |
4048 | !(db_table_str = new spider_string[spider_share->all_link_count]) |
4049 | ) { |
4050 | error_num = HA_ERR_OUT_OF_MEM; |
4051 | goto error; |
4052 | } |
4053 | |
4054 | same_db_table_name = TRUE; |
4055 | first_tbl_nm = spider_share->tgt_table_names[0]; |
4056 | first_db_nm = spider_share->tgt_dbs[0]; |
4057 | table_nm_len = spider_share->tgt_table_names_lengths[0]; |
4058 | db_nm_len = spider_share->tgt_dbs_lengths[0]; |
4059 | first_tbl_nm_str = &table_names_str[0]; |
4060 | first_db_nm_str = &db_names_str[0]; |
4061 | first_db_tbl_str = &db_table_str[0]; |
4062 | for (roop_count = 0; roop_count < (int) spider_share->all_link_count; |
4063 | roop_count++) |
4064 | { |
4065 | table_names_str[roop_count].init_calc_mem(86); |
4066 | db_names_str[roop_count].init_calc_mem(87); |
4067 | db_table_str[roop_count].init_calc_mem(88); |
4068 | if (spider_share->sql_dbton_ids[roop_count] != dbton_id) |
4069 | continue; |
4070 | if (first_all_link_idx == -1) |
4071 | first_all_link_idx = roop_count; |
4072 | |
4073 | str = &table_names_str[roop_count]; |
4074 | if ( |
4075 | roop_count != 0 && |
4076 | same_db_table_name && |
4077 | spider_share->tgt_table_names_lengths[roop_count] == table_nm_len && |
4078 | !memcmp(first_tbl_nm, spider_share->tgt_table_names[roop_count], |
4079 | table_nm_len) |
4080 | ) { |
4081 | if (str->copy(*first_tbl_nm_str)) |
4082 | { |
4083 | error_num = HA_ERR_OUT_OF_MEM; |
4084 | goto error; |
4085 | } |
4086 | } else { |
4087 | str->set_charset(spider_share->access_charset); |
4088 | if ((error_num = spider_db_append_name_with_quote_str(str, |
4089 | spider_share->tgt_table_names[roop_count], dbton_id))) |
4090 | goto error; |
4091 | if (roop_count) |
4092 | { |
4093 | same_db_table_name = FALSE; |
4094 | DBUG_PRINT("info" , ("spider found different table name %s" , |
4095 | spider_share->tgt_table_names[roop_count])); |
4096 | if (str->length() > table_nm_max_length) |
4097 | table_nm_max_length = str->length(); |
4098 | } else |
4099 | table_nm_max_length = str->length(); |
4100 | } |
4101 | |
4102 | str = &db_names_str[roop_count]; |
4103 | if ( |
4104 | roop_count != 0 && |
4105 | same_db_table_name && |
4106 | spider_share->tgt_dbs_lengths[roop_count] == db_nm_len && |
4107 | !memcmp(first_db_nm, spider_share->tgt_dbs[roop_count], |
4108 | db_nm_len) |
4109 | ) { |
4110 | if (str->copy(*first_db_nm_str)) |
4111 | { |
4112 | error_num = HA_ERR_OUT_OF_MEM; |
4113 | goto error; |
4114 | } |
4115 | } else { |
4116 | str->set_charset(spider_share->access_charset); |
4117 | if ((error_num = spider_db_append_name_with_quote_str(str, |
4118 | spider_share->tgt_dbs[roop_count], dbton_id))) |
4119 | goto error; |
4120 | if (roop_count) |
4121 | { |
4122 | same_db_table_name = FALSE; |
4123 | DBUG_PRINT("info" , ("spider found different db name %s" , |
4124 | spider_share->tgt_dbs[roop_count])); |
4125 | if (str->length() > db_nm_max_length) |
4126 | db_nm_max_length = str->length(); |
4127 | } else |
4128 | db_nm_max_length = str->length(); |
4129 | } |
4130 | |
4131 | str = &db_table_str[roop_count]; |
4132 | if ( |
4133 | roop_count != 0 && |
4134 | same_db_table_name |
4135 | ) { |
4136 | if (str->copy(*first_db_tbl_str)) |
4137 | { |
4138 | error_num = HA_ERR_OUT_OF_MEM; |
4139 | goto error; |
4140 | } |
4141 | } else { |
4142 | str->set_charset(spider_share->access_charset); |
4143 | if ((error_num = append_table_name(str, roop_count))) |
4144 | goto error; |
4145 | } |
4146 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
4147 | db_table_str_hash_value[roop_count] = my_calc_hash( |
4148 | &spider_open_connections, (uchar*) str->ptr(), str->length()); |
4149 | #endif |
4150 | } |
4151 | DBUG_RETURN(0); |
4152 | |
4153 | error: |
4154 | if (db_table_str) |
4155 | { |
4156 | delete [] db_table_str; |
4157 | db_table_str = NULL; |
4158 | } |
4159 | if (db_names_str) |
4160 | { |
4161 | delete [] db_names_str; |
4162 | db_names_str = NULL; |
4163 | } |
4164 | if (table_names_str) |
4165 | { |
4166 | delete [] table_names_str; |
4167 | table_names_str = NULL; |
4168 | } |
4169 | DBUG_RETURN(error_num); |
4170 | } |
4171 | |
4172 | void spider_handlersocket_share::free_table_names_str() |
4173 | { |
4174 | DBUG_ENTER("spider_handlersocket_share::free_table_names_str" ); |
4175 | if (db_table_str) |
4176 | { |
4177 | delete [] db_table_str; |
4178 | db_table_str = NULL; |
4179 | } |
4180 | if (db_names_str) |
4181 | { |
4182 | delete [] db_names_str; |
4183 | db_names_str = NULL; |
4184 | } |
4185 | if (table_names_str) |
4186 | { |
4187 | delete [] table_names_str; |
4188 | table_names_str = NULL; |
4189 | } |
4190 | DBUG_VOID_RETURN; |
4191 | } |
4192 | |
4193 | int spider_handlersocket_share::create_column_name_str() |
4194 | { |
4195 | spider_string *str; |
4196 | int error_num; |
4197 | Field **field; |
4198 | TABLE_SHARE *table_share = spider_share->table_share; |
4199 | uint dbton_id = spider_dbton_handlersocket.dbton_id; |
4200 | DBUG_ENTER("spider_handlersocket_share::create_column_name_str" ); |
4201 | if ( |
4202 | table_share->fields && |
4203 | !(column_name_str = new spider_string[table_share->fields]) |
4204 | ) |
4205 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4206 | for (field = table_share->field, str = column_name_str; |
4207 | *field; field++, str++) |
4208 | { |
4209 | str->init_calc_mem(202); |
4210 | str->set_charset(spider_share->access_charset); |
4211 | if ((error_num = spider_db_append_name_with_quote_str(str, |
4212 | (char *) (*field)->field_name.str, dbton_id))) |
4213 | goto error; |
4214 | } |
4215 | DBUG_RETURN(0); |
4216 | |
4217 | error: |
4218 | if (column_name_str) |
4219 | { |
4220 | delete [] column_name_str; |
4221 | column_name_str = NULL; |
4222 | } |
4223 | DBUG_RETURN(error_num); |
4224 | } |
4225 | |
4226 | void spider_handlersocket_share::free_column_name_str() |
4227 | { |
4228 | DBUG_ENTER("spider_handlersocket_share::free_column_name_str" ); |
4229 | if (column_name_str) |
4230 | { |
4231 | delete [] column_name_str; |
4232 | column_name_str = NULL; |
4233 | } |
4234 | DBUG_VOID_RETURN; |
4235 | } |
4236 | |
4237 | uint spider_handlersocket_share::get_column_name_length( |
4238 | uint field_index |
4239 | ) { |
4240 | DBUG_ENTER("spider_handlersocket_share::get_column_name_length" ); |
4241 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4242 | DBUG_RETURN(column_name_str[field_index].length()); |
4243 | } |
4244 | |
4245 | int spider_handlersocket_share::append_column_name( |
4246 | spider_string *str, |
4247 | uint field_index |
4248 | ) { |
4249 | int error_num; |
4250 | DBUG_ENTER("spider_handlersocket_share::append_column_name" ); |
4251 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4252 | error_num = spider_db_handlersocket_utility.append_name(str, |
4253 | column_name_str[field_index].ptr(), column_name_str[field_index].length()); |
4254 | DBUG_RETURN(error_num); |
4255 | } |
4256 | |
4257 | int spider_handlersocket_share::append_column_name_with_alias( |
4258 | spider_string *str, |
4259 | uint field_index, |
4260 | const char *alias, |
4261 | uint alias_length |
4262 | ) { |
4263 | DBUG_ENTER("spider_handlersocket_share::append_column_name_with_alias" ); |
4264 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4265 | if (str->reserve( |
4266 | alias_length + |
4267 | column_name_str[field_index].length() + |
4268 | /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) |
4269 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4270 | str->q_append(alias, alias_length); |
4271 | append_column_name(str, field_index); |
4272 | DBUG_RETURN(0); |
4273 | } |
4274 | |
4275 | bool spider_handlersocket_share::need_change_db_table_name() |
4276 | { |
4277 | DBUG_ENTER("spider_handlersocket_share::need_change_db_table_name" ); |
4278 | DBUG_RETURN(!same_db_table_name); |
4279 | } |
4280 | |
4281 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
4282 | int spider_handlersocket_share::discover_table_structure( |
4283 | SPIDER_TRX *trx, |
4284 | SPIDER_SHARE *spider_share, |
4285 | spider_string *str |
4286 | ) { |
4287 | DBUG_ENTER("spider_handlersocket_share::discover_table_structure" ); |
4288 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4289 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
4290 | } |
4291 | #endif |
4292 | |
4293 | spider_handlersocket_handler::spider_handlersocket_handler( |
4294 | ha_spider *spider, |
4295 | spider_handlersocket_share *db_share |
4296 | ) : spider_db_handler( |
4297 | spider, |
4298 | db_share |
4299 | ), |
4300 | handlersocket_share(db_share), |
4301 | link_for_hash(NULL) |
4302 | { |
4303 | DBUG_ENTER("spider_handlersocket_handler::spider_handlersocket_handler" ); |
4304 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4305 | spider_alloc_calc_mem_init(mem_calc, 187); |
4306 | spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); |
4307 | DBUG_VOID_RETURN; |
4308 | } |
4309 | |
4310 | spider_handlersocket_handler::~spider_handlersocket_handler() |
4311 | { |
4312 | DBUG_ENTER("spider_handlersocket_handler::~spider_handlersocket_handler" ); |
4313 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4314 | if (link_for_hash) |
4315 | { |
4316 | spider_free(spider_current_trx, link_for_hash, MYF(0)); |
4317 | } |
4318 | spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); |
4319 | DBUG_VOID_RETURN; |
4320 | } |
4321 | |
4322 | int spider_handlersocket_handler::init() |
4323 | { |
4324 | st_spider_share *share = spider->share; |
4325 | TABLE *table = spider->get_table(); |
4326 | DBUG_ENTER("spider_handlersocket_handler::init" ); |
4327 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4328 | if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *) |
4329 | spider_bulk_alloc_mem(spider_current_trx, 204, |
4330 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
4331 | &link_for_hash, |
4332 | sizeof(SPIDER_LINK_FOR_HASH) * share->link_count, |
4333 | &minimum_select_bitmap, |
4334 | table ? sizeof(uchar) * no_bytes_in_map(table->read_set) : 0, |
4335 | NullS)) |
4336 | ) { |
4337 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4338 | } |
4339 | uint roop_count; |
4340 | for (roop_count = 0; roop_count < share->link_count; roop_count++) |
4341 | { |
4342 | link_for_hash[roop_count].spider = spider; |
4343 | link_for_hash[roop_count].link_idx = roop_count; |
4344 | link_for_hash[roop_count].db_table_str = |
4345 | &handlersocket_share->db_table_str[roop_count]; |
4346 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
4347 | link_for_hash[roop_count].db_table_str_hash_value = |
4348 | handlersocket_share->db_table_str_hash_value[roop_count]; |
4349 | #endif |
4350 | } |
4351 | hs_sql.init_calc_mem(63); |
4352 | hs_sql.set_charset(share->access_charset); |
4353 | hs_keys.init(); |
4354 | hs_upds.init(); |
4355 | hs_strs.init(); |
4356 | DBUG_RETURN(0); |
4357 | } |
4358 | |
4359 | int spider_handlersocket_handler::append_index_hint( |
4360 | spider_string *str, |
4361 | int link_idx, |
4362 | ulong sql_type |
4363 | ) |
4364 | { |
4365 | DBUG_ENTER("spider_handlersocket_handler::append_index_hint" ); |
4366 | DBUG_RETURN(0); |
4367 | } |
4368 | |
4369 | int spider_handlersocket_handler::append_table_name_with_adjusting( |
4370 | spider_string *str, |
4371 | int link_idx, |
4372 | ulong sql_type |
4373 | ) { |
4374 | DBUG_ENTER("spider_handlersocket_handler::append_table_name_with_adjusting" ); |
4375 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4376 | DBUG_ASSERT(0); |
4377 | DBUG_RETURN(0); |
4378 | } |
4379 | |
4380 | int spider_handlersocket_handler::append_tmp_table_and_sql_for_bka( |
4381 | const key_range *start_key |
4382 | ) { |
4383 | DBUG_ENTER("spider_handlersocket_handler::append_tmp_table_and_sql_for_bka" ); |
4384 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4385 | DBUG_ASSERT(0); |
4386 | DBUG_RETURN(0); |
4387 | } |
4388 | |
4389 | int spider_handlersocket_handler::reuse_tmp_table_and_sql_for_bka() |
4390 | { |
4391 | DBUG_ENTER("spider_handlersocket_handler::reuse_tmp_table_and_sql_for_bka" ); |
4392 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4393 | DBUG_ASSERT(0); |
4394 | DBUG_RETURN(0); |
4395 | } |
4396 | |
4397 | int spider_handlersocket_handler::append_union_table_and_sql_for_bka( |
4398 | const key_range *start_key |
4399 | ) { |
4400 | DBUG_ENTER("spider_handlersocket_handler::append_union_table_and_sql_for_bka" ); |
4401 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4402 | DBUG_ASSERT(0); |
4403 | DBUG_RETURN(0); |
4404 | } |
4405 | |
4406 | int spider_handlersocket_handler::reuse_union_table_and_sql_for_bka() |
4407 | { |
4408 | DBUG_ENTER("spider_handlersocket_handler::reuse_union_table_and_sql_for_bka" ); |
4409 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4410 | DBUG_ASSERT(0); |
4411 | DBUG_RETURN(0); |
4412 | } |
4413 | |
4414 | int spider_handlersocket_handler::append_insert_for_recovery( |
4415 | ulong sql_type, |
4416 | int link_idx |
4417 | ) { |
4418 | DBUG_ENTER("spider_handlersocket_handler::append_insert_for_recovery" ); |
4419 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4420 | DBUG_ASSERT(0); |
4421 | DBUG_RETURN(0); |
4422 | } |
4423 | |
4424 | int spider_handlersocket_handler::append_update( |
4425 | const TABLE *table, |
4426 | my_ptrdiff_t ptr_diff |
4427 | ) { |
4428 | DBUG_ENTER("spider_handlersocket_handler::append_update" ); |
4429 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4430 | DBUG_ASSERT(0); |
4431 | DBUG_RETURN(0); |
4432 | } |
4433 | |
4434 | int spider_handlersocket_handler::append_update( |
4435 | const TABLE *table, |
4436 | my_ptrdiff_t ptr_diff, |
4437 | int link_idx |
4438 | ) { |
4439 | DBUG_ENTER("spider_handlersocket_handler::append_update" ); |
4440 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4441 | DBUG_ASSERT(0); |
4442 | DBUG_RETURN(0); |
4443 | } |
4444 | |
4445 | int spider_handlersocket_handler::append_delete( |
4446 | const TABLE *table, |
4447 | my_ptrdiff_t ptr_diff |
4448 | ) { |
4449 | DBUG_ENTER("spider_handlersocket_handler::append_delete" ); |
4450 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4451 | DBUG_ASSERT(0); |
4452 | DBUG_RETURN(0); |
4453 | } |
4454 | |
4455 | int spider_handlersocket_handler::append_delete( |
4456 | const TABLE *table, |
4457 | my_ptrdiff_t ptr_diff, |
4458 | int link_idx |
4459 | ) { |
4460 | DBUG_ENTER("spider_handlersocket_handler::append_delete" ); |
4461 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4462 | DBUG_ASSERT(0); |
4463 | DBUG_RETURN(0); |
4464 | } |
4465 | |
4466 | int spider_handlersocket_handler::append_insert_part() |
4467 | { |
4468 | DBUG_ENTER("spider_handlersocket_handler::append_insert_part" ); |
4469 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4470 | DBUG_ASSERT(0); |
4471 | DBUG_RETURN(0); |
4472 | } |
4473 | |
4474 | int spider_handlersocket_handler::append_update_part() |
4475 | { |
4476 | DBUG_ENTER("spider_handlersocket_handler::append_update_part" ); |
4477 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4478 | DBUG_ASSERT(0); |
4479 | DBUG_RETURN(0); |
4480 | } |
4481 | |
4482 | int spider_handlersocket_handler::append_delete_part() |
4483 | { |
4484 | DBUG_ENTER("spider_handlersocket_handler::append_delete_part" ); |
4485 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4486 | DBUG_ASSERT(0); |
4487 | DBUG_RETURN(0); |
4488 | } |
4489 | |
4490 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
4491 | int spider_handlersocket_handler::append_increment_update_set_part() |
4492 | { |
4493 | DBUG_ENTER("spider_handlersocket_handler::append_increment_update_set_part" ); |
4494 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4495 | DBUG_ASSERT(0); |
4496 | DBUG_RETURN(0); |
4497 | } |
4498 | #endif |
4499 | |
4500 | int spider_handlersocket_handler::append_update_set_part() |
4501 | { |
4502 | DBUG_ENTER("spider_handlersocket_handler::append_update_set_part" ); |
4503 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4504 | DBUG_ASSERT(0); |
4505 | DBUG_RETURN(0); |
4506 | } |
4507 | |
4508 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
4509 | int spider_handlersocket_handler::append_direct_update_set_part() |
4510 | { |
4511 | SPIDER_SHARE *share = spider->share; |
4512 | DBUG_ENTER("spider_handlersocket_handler::append_direct_update_set_part" ); |
4513 | if ( |
4514 | spider->do_direct_update && |
4515 | (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) |
4516 | ) { |
4517 | DBUG_PRINT("info" ,("spider add set for DU SPIDER_SQL_KIND_HS" )); |
4518 | size_t roop_count; |
4519 | Field *field; |
4520 | hs_adding_keys = FALSE; |
4521 | for (roop_count = 0; roop_count < spider->hs_pushed_ret_fields_num; |
4522 | roop_count++) |
4523 | { |
4524 | Field *top_table_field = |
4525 | spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); |
4526 | if (!(field = spider->field_exchange(top_table_field))) |
4527 | continue; |
4528 | if (top_table_field->is_null()) |
4529 | { |
4530 | hs_upds.push_back(spider_null_string_ref); |
4531 | } else { |
4532 | if (spider_db_handlersocket_utility. |
4533 | append_column_value(spider, NULL, top_table_field, NULL, |
4534 | share->access_charset)) |
4535 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4536 | } |
4537 | } |
4538 | } |
4539 | DBUG_RETURN(0); |
4540 | } |
4541 | #endif |
4542 | |
4543 | int spider_handlersocket_handler::append_minimum_select_without_quote( |
4544 | spider_string *str |
4545 | ) { |
4546 | TABLE *table = spider->get_table(); |
4547 | Field **field; |
4548 | int field_length; |
4549 | bool appended = FALSE; |
4550 | DBUG_ENTER("spider_handlersocket_handler::append_minimum_select_without_quote" ); |
4551 | minimum_select_bitmap_create(); |
4552 | for (field = table->field; *field; field++) |
4553 | { |
4554 | if (minimum_select_bit_is_set((*field)->field_index)) |
4555 | { |
4556 | /* |
4557 | spider_set_bit(minimum_select_bitmap, (*field)->field_index); |
4558 | */ |
4559 | field_length = |
4560 | handlersocket_share->column_name_str[(*field)->field_index].length(); |
4561 | if (str->reserve(field_length + SPIDER_SQL_COMMA_LEN)) |
4562 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4563 | str->q_append( |
4564 | handlersocket_share->column_name_str[(*field)->field_index].ptr(), |
4565 | handlersocket_share->column_name_str[(*field)->field_index].length()); |
4566 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
4567 | appended = TRUE; |
4568 | } |
4569 | } |
4570 | if (appended) |
4571 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
4572 | DBUG_RETURN(0); |
4573 | } |
4574 | |
4575 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
4576 | int spider_handlersocket_handler::append_minimum_select_by_field_idx_list( |
4577 | spider_string *str, |
4578 | uint32 *field_idxs, |
4579 | size_t field_idxs_num |
4580 | ) { |
4581 | Field *field; |
4582 | int roop_count, field_length; |
4583 | bool appended = FALSE; |
4584 | DBUG_ENTER("spider_handlersocket_handler::append_minimum_select_by_field_idx_list" ); |
4585 | for (roop_count = 0; roop_count < (int) field_idxs_num; roop_count++) |
4586 | { |
4587 | field = spider->get_top_table_field(field_idxs[roop_count]); |
4588 | if ((field = spider->field_exchange(field))) |
4589 | { |
4590 | field_length = |
4591 | handlersocket_share->column_name_str[field->field_index].length(); |
4592 | if (str->reserve(field_length + SPIDER_SQL_COMMA_LEN)) |
4593 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
4594 | str->q_append( |
4595 | handlersocket_share->column_name_str[field->field_index].ptr(), |
4596 | handlersocket_share->column_name_str[field->field_index].length()); |
4597 | str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); |
4598 | appended = TRUE; |
4599 | } |
4600 | } |
4601 | if (appended) |
4602 | str->length(str->length() - SPIDER_SQL_COMMA_LEN); |
4603 | DBUG_RETURN(0); |
4604 | } |
4605 | |
4606 | int spider_handlersocket_handler::append_dup_update_pushdown_part( |
4607 | const char *alias, |
4608 | uint alias_length |
4609 | ) { |
4610 | DBUG_ENTER("spider_handlersocket_handler::append_dup_update_pushdown_part" ); |
4611 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4612 | DBUG_ASSERT(0); |
4613 | DBUG_RETURN(0); |
4614 | } |
4615 | |
4616 | int spider_handlersocket_handler::append_update_columns_part( |
4617 | const char *alias, |
4618 | uint alias_length |
4619 | ) { |
4620 | DBUG_ENTER("spider_handlersocket_handler::append_update_columns_part" ); |
4621 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4622 | DBUG_ASSERT(0); |
4623 | DBUG_RETURN(0); |
4624 | } |
4625 | |
4626 | int spider_handlersocket_handler::check_update_columns_part() |
4627 | { |
4628 | DBUG_ENTER("spider_handlersocket_handler::check_update_columns_part" ); |
4629 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4630 | DBUG_ASSERT(0); |
4631 | DBUG_RETURN(0); |
4632 | } |
4633 | #endif |
4634 | |
4635 | int spider_handlersocket_handler::append_select_part( |
4636 | ulong sql_type |
4637 | ) { |
4638 | DBUG_ENTER("spider_handlersocket_handler::append_select_part" ); |
4639 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4640 | DBUG_ASSERT(0); |
4641 | DBUG_RETURN(0); |
4642 | } |
4643 | |
4644 | int spider_handlersocket_handler::append_table_select_part( |
4645 | ulong sql_type |
4646 | ) { |
4647 | DBUG_ENTER("spider_handlersocket_handler::append_table_select_part" ); |
4648 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4649 | DBUG_ASSERT(0); |
4650 | DBUG_RETURN(0); |
4651 | } |
4652 | |
4653 | int spider_handlersocket_handler::append_key_select_part( |
4654 | ulong sql_type, |
4655 | uint idx |
4656 | ) { |
4657 | DBUG_ENTER("spider_handlersocket_handler::append_key_select_part" ); |
4658 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4659 | DBUG_ASSERT(0); |
4660 | DBUG_RETURN(0); |
4661 | } |
4662 | |
4663 | int spider_handlersocket_handler::append_minimum_select_part( |
4664 | ulong sql_type |
4665 | ) { |
4666 | DBUG_ENTER("spider_handlersocket_handler::append_minimum_select_part" ); |
4667 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4668 | DBUG_ASSERT(0); |
4669 | DBUG_RETURN(0); |
4670 | } |
4671 | |
4672 | int spider_handlersocket_handler::append_hint_after_table_part( |
4673 | ulong sql_type |
4674 | ) { |
4675 | DBUG_ENTER("spider_handlersocket_handler::append_hint_after_table_part" ); |
4676 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4677 | DBUG_ASSERT(0); |
4678 | DBUG_RETURN(0); |
4679 | } |
4680 | |
4681 | void spider_handlersocket_handler::set_where_pos( |
4682 | ulong sql_type |
4683 | ) { |
4684 | DBUG_ENTER("spider_handlersocket_handler::set_where_pos" ); |
4685 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4686 | DBUG_ASSERT(0); |
4687 | DBUG_VOID_RETURN; |
4688 | } |
4689 | |
4690 | void spider_handlersocket_handler::set_where_to_pos( |
4691 | ulong sql_type |
4692 | ) { |
4693 | DBUG_ENTER("spider_handlersocket_handler::set_where_to_pos" ); |
4694 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4695 | DBUG_ASSERT(0); |
4696 | DBUG_VOID_RETURN; |
4697 | } |
4698 | |
4699 | int spider_handlersocket_handler::check_item_type( |
4700 | Item *item |
4701 | ) { |
4702 | DBUG_ENTER("spider_handlersocket_handler::check_item_type" ); |
4703 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4704 | DBUG_ASSERT(0); |
4705 | DBUG_RETURN(0); |
4706 | } |
4707 | |
4708 | int spider_handlersocket_handler::append_values_connector_part( |
4709 | ulong sql_type |
4710 | ) { |
4711 | DBUG_ENTER("spider_handlersocket_handler::append_values_connector_part" ); |
4712 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4713 | DBUG_ASSERT(0); |
4714 | DBUG_RETURN(0); |
4715 | } |
4716 | |
4717 | int spider_handlersocket_handler::append_values_terminator_part( |
4718 | ulong sql_type |
4719 | ) { |
4720 | DBUG_ENTER("spider_handlersocket_handler::append_values_terminator_part" ); |
4721 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4722 | DBUG_ASSERT(0); |
4723 | DBUG_RETURN(0); |
4724 | } |
4725 | |
4726 | int spider_handlersocket_handler::append_union_table_connector_part( |
4727 | ulong sql_type |
4728 | ) { |
4729 | DBUG_ENTER("spider_handlersocket_handler::append_union_table_connector_part" ); |
4730 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4731 | DBUG_ASSERT(0); |
4732 | DBUG_RETURN(0); |
4733 | } |
4734 | |
4735 | int spider_handlersocket_handler::append_union_table_terminator_part( |
4736 | ulong sql_type |
4737 | ) { |
4738 | DBUG_ENTER("spider_handlersocket_handler::append_union_table_terminator_part" ); |
4739 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4740 | DBUG_ASSERT(0); |
4741 | DBUG_RETURN(0); |
4742 | } |
4743 | |
4744 | int spider_handlersocket_handler::append_key_column_values_part( |
4745 | const key_range *start_key, |
4746 | ulong sql_type |
4747 | ) { |
4748 | DBUG_ENTER("spider_handlersocket_handler::append_key_column_values_part" ); |
4749 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4750 | DBUG_ASSERT(0); |
4751 | DBUG_RETURN(0); |
4752 | } |
4753 | |
4754 | int spider_handlersocket_handler::append_key_column_values_with_name_part( |
4755 | const key_range *start_key, |
4756 | ulong sql_type |
4757 | ) { |
4758 | DBUG_ENTER("spider_handlersocket_handler::append_key_column_values_with_name_part" ); |
4759 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4760 | DBUG_ASSERT(0); |
4761 | DBUG_RETURN(0); |
4762 | } |
4763 | |
4764 | int spider_handlersocket_handler::append_key_where_part( |
4765 | const key_range *start_key, |
4766 | const key_range *end_key, |
4767 | ulong sql_type |
4768 | ) { |
4769 | int error_num; |
4770 | spider_string *str; |
4771 | bool set_order; |
4772 | DBUG_ENTER("spider_handlersocket_handler::append_key_where_part" ); |
4773 | switch (sql_type) |
4774 | { |
4775 | case SPIDER_SQL_TYPE_SELECT_HS: |
4776 | case SPIDER_SQL_TYPE_INSERT_HS: |
4777 | case SPIDER_SQL_TYPE_UPDATE_HS: |
4778 | case SPIDER_SQL_TYPE_DELETE_HS: |
4779 | str = &hs_sql; |
4780 | str->length(0); |
4781 | hs_adding_keys = TRUE; |
4782 | set_order = FALSE; |
4783 | break; |
4784 | default: |
4785 | DBUG_RETURN(0); |
4786 | } |
4787 | error_num = append_key_where(str, NULL, NULL, start_key, end_key, |
4788 | sql_type, set_order); |
4789 | DBUG_RETURN(error_num); |
4790 | } |
4791 | |
4792 | int spider_handlersocket_handler::append_key_where( |
4793 | spider_string *str, |
4794 | spider_string *str_part, |
4795 | spider_string *str_part2, |
4796 | const key_range *start_key, |
4797 | const key_range *end_key, |
4798 | ulong sql_type, |
4799 | bool set_order |
4800 | ) { |
4801 | int error_num; |
4802 | DBUG_ENTER("spider_handlersocket_handler::append_key_where" ); |
4803 | error_num = spider_db_append_key_where_internal(str, str_part, str_part2, |
4804 | start_key, end_key, spider, set_order, sql_type, |
4805 | spider_dbton_handlersocket.dbton_id); |
4806 | DBUG_RETURN(error_num); |
4807 | } |
4808 | |
4809 | int spider_handlersocket_handler::append_is_null_part( |
4810 | ulong sql_type, |
4811 | KEY_PART_INFO *key_part, |
4812 | const key_range *key, |
4813 | const uchar **ptr, |
4814 | bool key_eq, |
4815 | bool tgt_final |
4816 | ) { |
4817 | int error_num; |
4818 | spider_string *str; |
4819 | DBUG_ENTER("spider_handlersocket_handler::append_is_null_part" ); |
4820 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4821 | switch (sql_type) |
4822 | { |
4823 | case SPIDER_SQL_TYPE_SELECT_HS: |
4824 | case SPIDER_SQL_TYPE_INSERT_HS: |
4825 | case SPIDER_SQL_TYPE_UPDATE_HS: |
4826 | case SPIDER_SQL_TYPE_DELETE_HS: |
4827 | str = &hs_sql; |
4828 | break; |
4829 | default: |
4830 | DBUG_RETURN(0); |
4831 | } |
4832 | error_num = append_is_null(sql_type, str, NULL, NULL, key_part, key, ptr, |
4833 | key_eq, tgt_final); |
4834 | DBUG_RETURN(error_num); |
4835 | } |
4836 | |
4837 | int spider_handlersocket_handler::append_is_null( |
4838 | ulong sql_type, |
4839 | spider_string *str, |
4840 | spider_string *str_part, |
4841 | spider_string *str_part2, |
4842 | KEY_PART_INFO *key_part, |
4843 | const key_range *key, |
4844 | const uchar **ptr, |
4845 | bool key_eq, |
4846 | bool tgt_final |
4847 | ) { |
4848 | DBUG_ENTER("spider_handlersocket_handler::append_is_null" ); |
4849 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4850 | if (key_part->null_bit) |
4851 | { |
4852 | if (*(*ptr)++) |
4853 | { |
4854 | hs_keys.push_back(spider_null_string_ref); |
4855 | DBUG_RETURN(-1); |
4856 | } |
4857 | } |
4858 | DBUG_RETURN(0); |
4859 | } |
4860 | |
4861 | int spider_handlersocket_handler::append_where_terminator_part( |
4862 | ulong sql_type, |
4863 | bool set_order, |
4864 | int key_count |
4865 | ) { |
4866 | DBUG_ENTER("spider_handlersocket_handler::append_where_terminator_part" ); |
4867 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4868 | DBUG_RETURN(0); |
4869 | } |
4870 | |
4871 | int spider_handlersocket_handler::append_match_where_part( |
4872 | ulong sql_type |
4873 | ) { |
4874 | DBUG_ENTER("spider_handlersocket_handler::append_match_where_part" ); |
4875 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4876 | DBUG_ASSERT(0); |
4877 | DBUG_RETURN(0); |
4878 | } |
4879 | |
4880 | int spider_handlersocket_handler::append_condition_part( |
4881 | const char *alias, |
4882 | uint alias_length, |
4883 | ulong sql_type, |
4884 | bool test_flg |
4885 | ) { |
4886 | DBUG_ENTER("spider_handlersocket_handler::append_condition_part" ); |
4887 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4888 | DBUG_RETURN(0); |
4889 | } |
4890 | |
4891 | int spider_handlersocket_handler::append_match_select_part( |
4892 | ulong sql_type, |
4893 | const char *alias, |
4894 | uint alias_length |
4895 | ) { |
4896 | DBUG_ENTER("spider_handlersocket_handler::append_match_select_part" ); |
4897 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4898 | DBUG_ASSERT(0); |
4899 | DBUG_RETURN(0); |
4900 | } |
4901 | |
4902 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
4903 | int spider_handlersocket_handler::append_sum_select_part( |
4904 | ulong sql_type, |
4905 | const char *alias, |
4906 | uint alias_length |
4907 | ) { |
4908 | DBUG_ENTER("spider_handlersocket_handler::append_sum_select_part" ); |
4909 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4910 | DBUG_ASSERT(0); |
4911 | DBUG_RETURN(0); |
4912 | } |
4913 | #endif |
4914 | |
4915 | void spider_handlersocket_handler::set_order_pos( |
4916 | ulong sql_type |
4917 | ) { |
4918 | DBUG_ENTER("spider_handlersocket_handler::set_order_pos" ); |
4919 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4920 | DBUG_ASSERT(0); |
4921 | DBUG_VOID_RETURN; |
4922 | } |
4923 | |
4924 | void spider_handlersocket_handler::set_order_to_pos( |
4925 | ulong sql_type |
4926 | ) { |
4927 | DBUG_ENTER("spider_handlersocket_handler::set_order_to_pos" ); |
4928 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4929 | DBUG_ASSERT(0); |
4930 | DBUG_VOID_RETURN; |
4931 | } |
4932 | |
4933 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
4934 | int spider_handlersocket_handler::append_group_by_part( |
4935 | const char *alias, |
4936 | uint alias_length, |
4937 | ulong sql_type |
4938 | ) { |
4939 | DBUG_ENTER("spider_handlersocket_handler::append_group_by_part" ); |
4940 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4941 | DBUG_ASSERT(0); |
4942 | DBUG_RETURN(0); |
4943 | } |
4944 | #endif |
4945 | |
4946 | int spider_handlersocket_handler::append_key_order_for_merge_with_alias_part( |
4947 | const char *alias, |
4948 | uint alias_length, |
4949 | ulong sql_type |
4950 | ) { |
4951 | DBUG_ENTER("spider_handlersocket_handler::append_key_order_for_merge_with_alias_part" ); |
4952 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4953 | DBUG_ASSERT(0); |
4954 | DBUG_RETURN(0); |
4955 | } |
4956 | |
4957 | int spider_handlersocket_handler::append_key_order_for_direct_order_limit_with_alias_part( |
4958 | const char *alias, |
4959 | uint alias_length, |
4960 | ulong sql_type |
4961 | ) { |
4962 | DBUG_ENTER("spider_handlersocket_handler::append_key_order_for_direct_order_limit_with_alias_part" ); |
4963 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4964 | DBUG_ASSERT(0); |
4965 | DBUG_RETURN(0); |
4966 | } |
4967 | |
4968 | int spider_handlersocket_handler::append_key_order_with_alias_part( |
4969 | const char *alias, |
4970 | uint alias_length, |
4971 | ulong sql_type |
4972 | ) { |
4973 | DBUG_ENTER("spider_handlersocket_handler::append_key_order_with_alias_part" ); |
4974 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4975 | DBUG_ASSERT(0); |
4976 | DBUG_RETURN(0); |
4977 | } |
4978 | |
4979 | int spider_handlersocket_handler::append_limit_part( |
4980 | longlong offset, |
4981 | longlong limit, |
4982 | ulong sql_type |
4983 | ) { |
4984 | DBUG_ENTER("spider_handlersocket_handler::append_limit_part" ); |
4985 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
4986 | DBUG_PRINT("info" , ("spider offset=%lld" , offset)); |
4987 | DBUG_PRINT("info" , ("spider limit=%lld" , limit)); |
4988 | hs_skip = (int) offset; |
4989 | hs_limit = (int) limit; |
4990 | DBUG_RETURN(0); |
4991 | } |
4992 | |
4993 | int spider_handlersocket_handler::reappend_limit_part( |
4994 | longlong offset, |
4995 | longlong limit, |
4996 | ulong sql_type |
4997 | ) { |
4998 | DBUG_ENTER("spider_handlersocket_handler::reappend_limit_part" ); |
4999 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5000 | DBUG_ASSERT(0); |
5001 | DBUG_RETURN(0); |
5002 | } |
5003 | |
5004 | int spider_handlersocket_handler::append_select_lock_part( |
5005 | ulong sql_type |
5006 | ) { |
5007 | DBUG_ENTER("spider_handlersocket_handler::append_select_lock_part" ); |
5008 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5009 | DBUG_ASSERT(0); |
5010 | DBUG_RETURN(0); |
5011 | } |
5012 | |
5013 | int spider_handlersocket_handler::append_union_all_start_part( |
5014 | ulong sql_type |
5015 | ) { |
5016 | DBUG_ENTER("spider_handlersocket_handler::append_union_all_start_part" ); |
5017 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5018 | DBUG_ASSERT(0); |
5019 | DBUG_RETURN(0); |
5020 | } |
5021 | |
5022 | int spider_handlersocket_handler::append_union_all_part( |
5023 | ulong sql_type |
5024 | ) { |
5025 | DBUG_ENTER("spider_handlersocket_handler::append_union_all_part" ); |
5026 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5027 | DBUG_ASSERT(0); |
5028 | DBUG_RETURN(0); |
5029 | } |
5030 | |
5031 | int spider_handlersocket_handler::append_union_all_end_part( |
5032 | ulong sql_type |
5033 | ) { |
5034 | DBUG_ENTER("spider_handlersocket_handler::append_union_all_end_part" ); |
5035 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5036 | DBUG_ASSERT(0); |
5037 | DBUG_RETURN(0); |
5038 | } |
5039 | |
5040 | int spider_handlersocket_handler::append_multi_range_cnt_part( |
5041 | ulong sql_type, |
5042 | uint multi_range_cnt, |
5043 | bool with_comma |
5044 | ) { |
5045 | DBUG_ENTER("spider_handlersocket_handler::append_multi_range_cnt_part" ); |
5046 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5047 | DBUG_ASSERT(0); |
5048 | DBUG_RETURN(0); |
5049 | } |
5050 | |
5051 | int spider_handlersocket_handler::append_multi_range_cnt_with_name_part( |
5052 | ulong sql_type, |
5053 | uint multi_range_cnt |
5054 | ) { |
5055 | DBUG_ENTER("spider_handlersocket_handler::append_multi_range_cnt_with_name_part" ); |
5056 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5057 | DBUG_ASSERT(0); |
5058 | DBUG_RETURN(0); |
5059 | } |
5060 | |
5061 | int spider_handlersocket_handler::append_open_handler_part( |
5062 | ulong sql_type, |
5063 | uint handler_id, |
5064 | SPIDER_CONN *conn, |
5065 | int link_idx |
5066 | ) { |
5067 | int error_num; |
5068 | spider_string *str; |
5069 | DBUG_ENTER("spider_handlersocket_handler::append_open_handler_part" ); |
5070 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5071 | switch (sql_type) |
5072 | { |
5073 | case SPIDER_SQL_TYPE_OTHER_HS: |
5074 | str = &hs_sql; |
5075 | break; |
5076 | default: |
5077 | DBUG_RETURN(0); |
5078 | } |
5079 | error_num = append_open_handler(str, handler_id, conn, link_idx); |
5080 | DBUG_RETURN(error_num); |
5081 | } |
5082 | |
5083 | int spider_handlersocket_handler::append_open_handler( |
5084 | spider_string *str, |
5085 | uint handler_id, |
5086 | SPIDER_CONN *conn, |
5087 | int link_idx |
5088 | ) { |
5089 | int error_num; |
5090 | DBUG_ENTER("spider_handlersocket_handler::append_open_handler" ); |
5091 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5092 | if ( |
5093 | str->length() == 0 && |
5094 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
5095 | ( |
5096 | ( |
5097 | ( |
5098 | spider->sql_command == SQLCOM_HS_INSERT || |
5099 | spider->hs_pushed_ret_fields_num == MAX_FIELDS |
5100 | ) && |
5101 | #endif |
5102 | (error_num = append_minimum_select_without_quote(str)) |
5103 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
5104 | ) || |
5105 | ( |
5106 | ( |
5107 | spider->sql_command != SQLCOM_HS_INSERT && |
5108 | spider->hs_pushed_ret_fields_num < MAX_FIELDS |
5109 | ) && |
5110 | (error_num = append_minimum_select_by_field_idx_list(str, |
5111 | spider->hs_pushed_ret_fields, spider->hs_pushed_ret_fields_num)) |
5112 | ) |
5113 | ) |
5114 | #endif |
5115 | ) { |
5116 | DBUG_RETURN(error_num); |
5117 | } |
5118 | |
5119 | TABLE *table = spider->get_table(); |
5120 | SPIDER_SHARE *share = spider->share; |
5121 | DBUG_PRINT("info" ,("spider field list=%s" , str->c_ptr_safe())); |
5122 | if (!spider_bit_is_set(spider->db_request_phase, link_idx)) |
5123 | { |
5124 | spider_set_bit(spider->db_request_phase, link_idx); |
5125 | ++spider->db_request_id[link_idx]; |
5126 | } |
5127 | st_spider_db_request_key request_key; |
5128 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
5129 | request_key.query_id = spider->trx->thd->query_id; |
5130 | request_key.handler = spider; |
5131 | request_key.request_id = spider->db_request_id[link_idx]; |
5132 | request_key.next = NULL; |
5133 | conn->db_conn->append_open_handler( |
5134 | handler_id, |
5135 | share->tgt_dbs[spider->conn_link_idx[link_idx]], |
5136 | share->tgt_table_names[spider->conn_link_idx[link_idx]], |
5137 | spider->active_index < MAX_KEY ? |
5138 | table->s->key_info[spider->active_index].name : |
5139 | "0" , |
5140 | str->c_ptr_safe(), |
5141 | &request_key |
5142 | ); |
5143 | DBUG_RETURN(0); |
5144 | } |
5145 | |
5146 | int spider_handlersocket_handler::append_close_handler_part( |
5147 | ulong sql_type, |
5148 | int link_idx |
5149 | ) { |
5150 | DBUG_ENTER("spider_handlersocket_handler::append_close_handler_part" ); |
5151 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5152 | DBUG_ASSERT(0); |
5153 | DBUG_RETURN(0); |
5154 | } |
5155 | |
5156 | int spider_handlersocket_handler::append_insert_terminator_part( |
5157 | ulong sql_type |
5158 | ) { |
5159 | DBUG_ENTER("spider_handlersocket_handler::append_insert_terminator_part" ); |
5160 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5161 | DBUG_ASSERT(0); |
5162 | DBUG_RETURN(0); |
5163 | } |
5164 | |
5165 | int spider_handlersocket_handler::append_insert_values_part( |
5166 | ulong sql_type |
5167 | ) { |
5168 | int error_num; |
5169 | spider_string *str; |
5170 | DBUG_ENTER("spider_mysql_handler::append_insert_values_part" ); |
5171 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5172 | switch (sql_type) |
5173 | { |
5174 | case SPIDER_SQL_TYPE_INSERT_HS: |
5175 | str = &hs_sql; |
5176 | break; |
5177 | default: |
5178 | DBUG_RETURN(0); |
5179 | } |
5180 | error_num = append_insert_values(str); |
5181 | DBUG_RETURN(error_num); |
5182 | } |
5183 | |
5184 | int spider_handlersocket_handler::append_insert_values( |
5185 | spider_string *str |
5186 | ) { |
5187 | SPIDER_SHARE *share = spider->share; |
5188 | TABLE *table = spider->get_table(); |
5189 | Field **field; |
5190 | DBUG_ENTER("spider_mysql_handler::append_insert_values" ); |
5191 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5192 | hs_adding_keys = FALSE; |
5193 | for (field = table->field; *field; field++) |
5194 | { |
5195 | DBUG_PRINT("info" ,("spider field_index=%u" , (*field)->field_index)); |
5196 | if ( |
5197 | bitmap_is_set(table->write_set, (*field)->field_index) || |
5198 | bitmap_is_set(table->read_set, (*field)->field_index) |
5199 | ) { |
5200 | #ifndef DBUG_OFF |
5201 | my_bitmap_map *tmp_map = |
5202 | dbug_tmp_use_all_columns(table, table->read_set); |
5203 | #endif |
5204 | DBUG_PRINT("info" ,("spider is_null()=%s" , |
5205 | (*field)->is_null() ? "TRUE" : "FALSE" )); |
5206 | DBUG_PRINT("info" ,("spider table->next_number_field=%p" , |
5207 | table->next_number_field)); |
5208 | DBUG_PRINT("info" ,("spider *field=%p" , *field)); |
5209 | DBUG_PRINT("info" ,("spider force_auto_increment=%s" , |
5210 | (table->next_number_field && spider->force_auto_increment) ? |
5211 | "TRUE" : "FALSE" )); |
5212 | if ( |
5213 | (*field)->is_null() || |
5214 | ( |
5215 | table->next_number_field == *field && |
5216 | !table->auto_increment_field_not_null && |
5217 | !spider->force_auto_increment |
5218 | ) |
5219 | ) { |
5220 | hs_upds.push_back(spider_null_string_ref); |
5221 | } else { |
5222 | spider_db_handlersocket_utility. |
5223 | append_column_value(spider, NULL, *field, NULL, |
5224 | share->access_charset); |
5225 | } |
5226 | #ifndef DBUG_OFF |
5227 | dbug_tmp_restore_column_map(table->read_set, tmp_map); |
5228 | #endif |
5229 | } |
5230 | } |
5231 | int error_num; |
5232 | int roop_count2; |
5233 | for ( |
5234 | roop_count2 = spider_conn_link_idx_next(share->link_statuses, |
5235 | spider->conn_link_idx, -1, share->link_count, |
5236 | SPIDER_LINK_STATUS_RECOVERY); |
5237 | roop_count2 < (int) share->link_count; |
5238 | roop_count2 = spider_conn_link_idx_next(share->link_statuses, |
5239 | spider->conn_link_idx, roop_count2, share->link_count, |
5240 | SPIDER_LINK_STATUS_RECOVERY) |
5241 | ) { |
5242 | if (spider->sql_kind[roop_count2] == SPIDER_SQL_KIND_HS) |
5243 | { |
5244 | SPIDER_CONN *conn = spider->hs_w_conns[roop_count2]; |
5245 | if (conn->dbton_id == spider_dbton_handlersocket.dbton_id) |
5246 | { |
5247 | if ((error_num = request_buf_insert(roop_count2))) |
5248 | DBUG_RETURN(error_num); |
5249 | #ifdef HA_CAN_BULK_ACCESS |
5250 | if (spider->is_bulk_access_clone) |
5251 | { |
5252 | spider->connection_ids[roop_count2] = conn->connection_id; |
5253 | spider_trx_add_bulk_access_conn(spider->trx, conn); |
5254 | } |
5255 | #endif |
5256 | } |
5257 | } |
5258 | } |
5259 | hs_upds.clear(); |
5260 | DBUG_RETURN(0); |
5261 | } |
5262 | |
5263 | int spider_handlersocket_handler::append_into_part( |
5264 | ulong sql_type |
5265 | ) { |
5266 | DBUG_ENTER("spider_handlersocket_handler::append_into_part" ); |
5267 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5268 | DBUG_ASSERT(0); |
5269 | DBUG_RETURN(0); |
5270 | } |
5271 | |
5272 | void spider_handlersocket_handler::set_insert_to_pos( |
5273 | ulong sql_type |
5274 | ) { |
5275 | DBUG_ENTER("spider_handlersocket_handler::set_insert_to_pos" ); |
5276 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5277 | DBUG_ASSERT(0); |
5278 | DBUG_VOID_RETURN; |
5279 | } |
5280 | |
5281 | int spider_handlersocket_handler::append_from_part( |
5282 | ulong sql_type, |
5283 | int link_idx |
5284 | ) { |
5285 | DBUG_ENTER("spider_handlersocket_handler::append_from_part" ); |
5286 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5287 | DBUG_ASSERT(0); |
5288 | DBUG_RETURN(0); |
5289 | } |
5290 | |
5291 | int spider_handlersocket_handler::append_delete_all_rows_part( |
5292 | ulong sql_type |
5293 | ) { |
5294 | DBUG_ENTER("spider_handlersocket_handler::append_delete_all_rows_part" ); |
5295 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5296 | DBUG_ASSERT(0); |
5297 | DBUG_RETURN(0); |
5298 | } |
5299 | |
5300 | int spider_handlersocket_handler::append_explain_select_part( |
5301 | key_range *start_key, |
5302 | key_range *end_key, |
5303 | ulong sql_type, |
5304 | int link_idx |
5305 | ) { |
5306 | DBUG_ENTER("spider_handlersocket_handler::append_explain_select_part" ); |
5307 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5308 | DBUG_ASSERT(0); |
5309 | DBUG_RETURN(0); |
5310 | } |
5311 | |
5312 | int spider_handlersocket_handler::is_sole_projection_field( |
5313 | uint16 field_index |
5314 | ) { |
5315 | DBUG_ENTER("spider_handlersocket_handler::is_sole_projection_field" ); |
5316 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5317 | DBUG_ASSERT(0); |
5318 | DBUG_RETURN(0); |
5319 | } |
5320 | |
5321 | bool spider_handlersocket_handler::is_bulk_insert_exec_period( |
5322 | bool bulk_end |
5323 | ) { |
5324 | DBUG_ENTER("spider_handlersocket_handler::is_bulk_insert_exec_period" ); |
5325 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5326 | if (!spider->bulk_insert || bulk_end) |
5327 | DBUG_RETURN(TRUE); |
5328 | DBUG_RETURN(FALSE); |
5329 | } |
5330 | |
5331 | bool spider_handlersocket_handler::sql_is_filled_up( |
5332 | ulong sql_type |
5333 | ) { |
5334 | DBUG_ENTER("spider_handlersocket_handler::sql_is_filled_up" ); |
5335 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5336 | DBUG_ASSERT(0); |
5337 | DBUG_RETURN(FALSE); |
5338 | } |
5339 | |
5340 | bool spider_handlersocket_handler::sql_is_empty( |
5341 | ulong sql_type |
5342 | ) { |
5343 | DBUG_ENTER("spider_handlersocket_handler::sql_is_empty" ); |
5344 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5345 | DBUG_ASSERT(0); |
5346 | DBUG_RETURN(FALSE); |
5347 | } |
5348 | |
5349 | bool spider_handlersocket_handler::support_multi_split_read() |
5350 | { |
5351 | DBUG_ENTER("spider_handlersocket_handler::support_multi_split_read" ); |
5352 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5353 | DBUG_ASSERT(0); |
5354 | DBUG_RETURN(FALSE); |
5355 | } |
5356 | |
5357 | bool spider_handlersocket_handler::support_bulk_update() |
5358 | { |
5359 | DBUG_ENTER("spider_handlersocket_handler::support_bulk_update" ); |
5360 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5361 | DBUG_ASSERT(0); |
5362 | DBUG_RETURN(FALSE); |
5363 | } |
5364 | |
5365 | int spider_handlersocket_handler::bulk_tmp_table_insert() |
5366 | { |
5367 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_insert" ); |
5368 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5369 | DBUG_ASSERT(0); |
5370 | DBUG_RETURN(0); |
5371 | } |
5372 | |
5373 | int spider_handlersocket_handler::bulk_tmp_table_insert( |
5374 | int link_idx |
5375 | ) { |
5376 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_insert" ); |
5377 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5378 | DBUG_ASSERT(0); |
5379 | DBUG_RETURN(0); |
5380 | } |
5381 | |
5382 | int spider_handlersocket_handler::bulk_tmp_table_end_bulk_insert() |
5383 | { |
5384 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_end_bulk_insert" ); |
5385 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5386 | DBUG_ASSERT(0); |
5387 | DBUG_RETURN(0); |
5388 | } |
5389 | |
5390 | int spider_handlersocket_handler::bulk_tmp_table_rnd_init() |
5391 | { |
5392 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_rnd_init" ); |
5393 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5394 | DBUG_ASSERT(0); |
5395 | DBUG_RETURN(0); |
5396 | } |
5397 | |
5398 | int spider_handlersocket_handler::bulk_tmp_table_rnd_next() |
5399 | { |
5400 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_rnd_next" ); |
5401 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5402 | DBUG_ASSERT(0); |
5403 | DBUG_RETURN(0); |
5404 | } |
5405 | |
5406 | int spider_handlersocket_handler::bulk_tmp_table_rnd_end() |
5407 | { |
5408 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_rnd_end" ); |
5409 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5410 | DBUG_ASSERT(0); |
5411 | DBUG_RETURN(0); |
5412 | } |
5413 | |
5414 | bool spider_handlersocket_handler::need_copy_for_update( |
5415 | int link_idx |
5416 | ) { |
5417 | DBUG_ENTER("spider_handlersocket_handler::need_copy_for_update" ); |
5418 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5419 | DBUG_ASSERT(0); |
5420 | DBUG_RETURN(TRUE); |
5421 | } |
5422 | |
5423 | bool spider_handlersocket_handler::bulk_tmp_table_created() |
5424 | { |
5425 | DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_created" ); |
5426 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5427 | DBUG_ASSERT(0); |
5428 | DBUG_RETURN(FALSE); |
5429 | } |
5430 | |
5431 | int spider_handlersocket_handler::mk_bulk_tmp_table_and_bulk_start() |
5432 | { |
5433 | DBUG_ENTER("spider_handlersocket_handler::mk_bulk_tmp_table_and_bulk_start" ); |
5434 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5435 | DBUG_ASSERT(0); |
5436 | DBUG_RETURN(0); |
5437 | } |
5438 | |
5439 | void spider_handlersocket_handler::rm_bulk_tmp_table() |
5440 | { |
5441 | DBUG_ENTER("spider_handlersocket_handler::rm_bulk_tmp_table" ); |
5442 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5443 | DBUG_ASSERT(0); |
5444 | DBUG_VOID_RETURN; |
5445 | } |
5446 | |
5447 | int spider_handlersocket_handler::insert_lock_tables_list( |
5448 | SPIDER_CONN *conn, |
5449 | int link_idx |
5450 | ) { |
5451 | DBUG_ENTER("spider_handlersocket_handler::insert_lock_tables_list" ); |
5452 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5453 | DBUG_RETURN(0); |
5454 | } |
5455 | |
5456 | int spider_handlersocket_handler::append_lock_tables_list( |
5457 | SPIDER_CONN *conn, |
5458 | int link_idx, |
5459 | int *appended |
5460 | ) { |
5461 | DBUG_ENTER("spider_handlersocket_handler::append_lock_tables_list" ); |
5462 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5463 | DBUG_RETURN(0); |
5464 | } |
5465 | |
5466 | int spider_handlersocket_handler::realloc_sql( |
5467 | ulong *realloced |
5468 | ) { |
5469 | THD *thd = spider->trx->thd; |
5470 | st_spider_share *share = spider->share; |
5471 | int init_sql_alloc_size = |
5472 | spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); |
5473 | DBUG_ENTER("spider_handlersocket_handler::realloc_sql" ); |
5474 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5475 | if ((int) hs_sql.alloced_length() > init_sql_alloc_size * 2) |
5476 | { |
5477 | hs_sql.free(); |
5478 | if (hs_sql.real_alloc(init_sql_alloc_size)) |
5479 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5480 | *realloced |= SPIDER_SQL_TYPE_FULL_HS; |
5481 | } |
5482 | DBUG_RETURN(0); |
5483 | } |
5484 | |
5485 | int spider_handlersocket_handler::reset_sql( |
5486 | ulong sql_type |
5487 | ) { |
5488 | DBUG_ENTER("spider_handlersocket_handler::reset_sql" ); |
5489 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5490 | if (sql_type & SPIDER_SQL_TYPE_FULL_HS) |
5491 | { |
5492 | hs_sql.length(0); |
5493 | } |
5494 | DBUG_RETURN(0); |
5495 | } |
5496 | |
5497 | int spider_handlersocket_handler::reset_keys( |
5498 | ulong sql_type |
5499 | ) { |
5500 | DBUG_ENTER("spider_handlersocket_handler::reset_keys" ); |
5501 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5502 | if (sql_type & SPIDER_SQL_TYPE_FULL_HS) |
5503 | { |
5504 | hs_keys.clear(); |
5505 | } |
5506 | DBUG_RETURN(0); |
5507 | } |
5508 | |
5509 | int spider_handlersocket_handler::reset_upds( |
5510 | ulong sql_type |
5511 | ) { |
5512 | DBUG_ENTER("spider_handlersocket_handler::reset_upds" ); |
5513 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5514 | if (sql_type & SPIDER_SQL_TYPE_FULL_HS) |
5515 | { |
5516 | hs_upds.clear(); |
5517 | } |
5518 | DBUG_RETURN(0); |
5519 | } |
5520 | |
5521 | int spider_handlersocket_handler::reset_strs( |
5522 | ulong sql_type |
5523 | ) { |
5524 | DBUG_ENTER("spider_handlersocket_handler::reset_strs" ); |
5525 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5526 | if (sql_type & SPIDER_SQL_TYPE_FULL_HS) |
5527 | { |
5528 | hs_strs.clear(); |
5529 | } |
5530 | DBUG_RETURN(0); |
5531 | } |
5532 | |
5533 | int spider_handlersocket_handler::reset_strs_pos( |
5534 | ulong sql_type |
5535 | ) { |
5536 | DBUG_ENTER("spider_handlersocket_handler::reset_strs_pos" ); |
5537 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5538 | if (sql_type & SPIDER_SQL_TYPE_FULL_HS) |
5539 | { |
5540 | hs_strs_pos = 0; |
5541 | } |
5542 | DBUG_RETURN(0); |
5543 | } |
5544 | |
5545 | int spider_handlersocket_handler::push_back_upds( |
5546 | SPIDER_HS_STRING_REF &info |
5547 | ) { |
5548 | int error_num; |
5549 | DBUG_ENTER("spider_handlersocket_handler::push_back_upds" ); |
5550 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5551 | error_num = hs_upds.push_back(info); |
5552 | DBUG_RETURN(error_num); |
5553 | } |
5554 | |
5555 | int spider_handlersocket_handler::request_buf_find( |
5556 | int link_idx |
5557 | ) { |
5558 | int error_num; |
5559 | spider_string *hs_str; |
5560 | SPIDER_CONN *conn; |
5561 | uint handler_id; |
5562 | DBUG_ENTER("spider_handlersocket_handler::request_buf_find" ); |
5563 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5564 | if (!(hs_str = hs_strs.add(&hs_strs_pos, hs_sql.ptr(), hs_sql.length()))) |
5565 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5566 | if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ) |
5567 | { |
5568 | conn = spider->hs_r_conns[link_idx]; |
5569 | handler_id = spider->r_handler_id[link_idx]; |
5570 | } else { |
5571 | conn = spider->hs_w_conns[link_idx]; |
5572 | handler_id = spider->w_handler_id[link_idx]; |
5573 | } |
5574 | if ((error_num = spider_db_conn_queue_action(conn))) |
5575 | DBUG_RETURN(error_num); |
5576 | if (!spider_bit_is_set(spider->db_request_phase, link_idx)) |
5577 | { |
5578 | spider_set_bit(spider->db_request_phase, link_idx); |
5579 | ++spider->db_request_id[link_idx]; |
5580 | } |
5581 | st_spider_db_request_key request_key; |
5582 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
5583 | request_key.query_id = spider->trx->thd->query_id; |
5584 | request_key.handler = spider; |
5585 | request_key.request_id = spider->db_request_id[link_idx]; |
5586 | request_key.next = NULL; |
5587 | conn->db_conn->append_select( |
5588 | handler_id, hs_str, &hs_keys, |
5589 | hs_limit, hs_skip, &request_key); |
5590 | DBUG_RETURN(0); |
5591 | } |
5592 | |
5593 | int spider_handlersocket_handler::request_buf_insert( |
5594 | int link_idx |
5595 | ) { |
5596 | int error_num; |
5597 | DBUG_ENTER("spider_handlersocket_handler::request_buf_insert" ); |
5598 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5599 | if ((error_num = spider_db_conn_queue_action(spider->hs_w_conns[link_idx]))) |
5600 | DBUG_RETURN(error_num); |
5601 | if (!spider_bit_is_set(spider->db_request_phase, link_idx)) |
5602 | { |
5603 | spider_set_bit(spider->db_request_phase, link_idx); |
5604 | ++spider->db_request_id[link_idx]; |
5605 | } |
5606 | st_spider_db_request_key request_key; |
5607 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
5608 | request_key.query_id = spider->trx->thd->query_id; |
5609 | request_key.handler = spider; |
5610 | request_key.request_id = spider->db_request_id[link_idx]; |
5611 | request_key.next = NULL; |
5612 | spider->hs_w_conns[link_idx]->db_conn->append_insert( |
5613 | spider->w_handler_id[link_idx], &hs_upds, &request_key); |
5614 | DBUG_RETURN(0); |
5615 | } |
5616 | |
5617 | int spider_handlersocket_handler::request_buf_update( |
5618 | int link_idx |
5619 | ) { |
5620 | int error_num; |
5621 | spider_string *hs_str; |
5622 | DBUG_ENTER("spider_handlersocket_handler::request_buf_update" ); |
5623 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5624 | if (!(hs_str = hs_strs.add(&hs_strs_pos, hs_sql.ptr(), hs_sql.length()))) |
5625 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5626 | if ((error_num = spider_db_conn_queue_action(spider->hs_w_conns[link_idx]))) |
5627 | DBUG_RETURN(error_num); |
5628 | if (!spider_bit_is_set(spider->db_request_phase, link_idx)) |
5629 | { |
5630 | spider_set_bit(spider->db_request_phase, link_idx); |
5631 | ++spider->db_request_id[link_idx]; |
5632 | } |
5633 | st_spider_db_request_key request_key; |
5634 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
5635 | request_key.query_id = spider->trx->thd->query_id; |
5636 | request_key.handler = spider; |
5637 | request_key.request_id = spider->db_request_id[link_idx]; |
5638 | request_key.next = NULL; |
5639 | spider->hs_w_conns[link_idx]->db_conn->append_update( |
5640 | spider->w_handler_id[link_idx], hs_str, &hs_keys, &hs_upds, |
5641 | hs_limit, hs_skip, |
5642 | spider->hs_increment, spider->hs_decrement, &request_key |
5643 | ); |
5644 | DBUG_RETURN(0); |
5645 | } |
5646 | |
5647 | int spider_handlersocket_handler::request_buf_delete( |
5648 | int link_idx |
5649 | ) { |
5650 | int error_num; |
5651 | spider_string *hs_str; |
5652 | DBUG_ENTER("spider_handlersocket_handler::request_buf_delete" ); |
5653 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5654 | if (!(hs_str = hs_strs.add(&hs_strs_pos, hs_sql.ptr(), hs_sql.length()))) |
5655 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5656 | if ((error_num = spider_db_conn_queue_action(spider->hs_w_conns[link_idx]))) |
5657 | DBUG_RETURN(error_num); |
5658 | if (!spider_bit_is_set(spider->db_request_phase, link_idx)) |
5659 | { |
5660 | spider_set_bit(spider->db_request_phase, link_idx); |
5661 | ++spider->db_request_id[link_idx]; |
5662 | } |
5663 | st_spider_db_request_key request_key; |
5664 | request_key.spider_thread_id = spider->trx->spider_thread_id; |
5665 | request_key.query_id = spider->trx->thd->query_id; |
5666 | request_key.handler = spider; |
5667 | request_key.request_id = spider->db_request_id[link_idx]; |
5668 | request_key.next = NULL; |
5669 | spider->hs_w_conns[link_idx]->db_conn->append_delete( |
5670 | spider->w_handler_id[link_idx], hs_str, &hs_keys, |
5671 | hs_limit, hs_skip, &request_key); |
5672 | DBUG_RETURN(0); |
5673 | } |
5674 | |
5675 | bool spider_handlersocket_handler::need_lock_before_set_sql_for_exec( |
5676 | ulong sql_type |
5677 | ) { |
5678 | DBUG_ENTER("spider_handlersocket_handler::need_lock_before_set_sql_for_exec" ); |
5679 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5680 | DBUG_RETURN(TRUE); |
5681 | } |
5682 | |
5683 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
5684 | int spider_handlersocket_handler::set_sql_for_exec( |
5685 | ulong sql_type, |
5686 | int link_idx, |
5687 | SPIDER_LINK_IDX_CHAIN *link_idx_chain |
5688 | ) { |
5689 | DBUG_ENTER("spider_handlersocket_handler::set_sql_for_exec" ); |
5690 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5691 | DBUG_ASSERT(0); |
5692 | DBUG_RETURN(0); |
5693 | } |
5694 | #endif |
5695 | |
5696 | int spider_handlersocket_handler::set_sql_for_exec( |
5697 | ulong sql_type, |
5698 | int link_idx |
5699 | ) { |
5700 | DBUG_ENTER("spider_handlersocket_handler::set_sql_for_exec" ); |
5701 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5702 | if (sql_type & SPIDER_SQL_TYPE_SELECT_HS) |
5703 | { |
5704 | DBUG_RETURN(request_buf_find(link_idx)); |
5705 | } |
5706 | if (sql_type & SPIDER_SQL_TYPE_INSERT_HS) |
5707 | { |
5708 | DBUG_RETURN(request_buf_insert(link_idx)); |
5709 | } |
5710 | if (sql_type & SPIDER_SQL_TYPE_UPDATE_HS) |
5711 | { |
5712 | DBUG_RETURN(request_buf_update(link_idx)); |
5713 | } |
5714 | if (sql_type & SPIDER_SQL_TYPE_DELETE_HS) |
5715 | { |
5716 | DBUG_RETURN(request_buf_delete(link_idx)); |
5717 | } |
5718 | DBUG_RETURN(0); |
5719 | } |
5720 | |
5721 | int spider_handlersocket_handler::set_sql_for_exec( |
5722 | spider_db_copy_table *tgt_ct, |
5723 | ulong sql_type |
5724 | ) { |
5725 | DBUG_ENTER("spider_handlersocket_handler::set_sql_for_exec" ); |
5726 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5727 | DBUG_ASSERT(0); |
5728 | DBUG_RETURN(0); |
5729 | } |
5730 | |
5731 | int spider_handlersocket_handler::execute_sql( |
5732 | ulong sql_type, |
5733 | SPIDER_CONN *conn, |
5734 | int quick_mode, |
5735 | int *need_mon |
5736 | ) { |
5737 | DBUG_ENTER("spider_handlersocket_handler::execute_sql" ); |
5738 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5739 | if (!(sql_type & SPIDER_SQL_TYPE_FULL_HS)) |
5740 | { |
5741 | /* nothing to do */ |
5742 | DBUG_RETURN(0); |
5743 | } |
5744 | DBUG_RETURN(spider_db_query( |
5745 | conn, |
5746 | NULL, |
5747 | 0, |
5748 | quick_mode, |
5749 | need_mon |
5750 | )); |
5751 | } |
5752 | |
5753 | int spider_handlersocket_handler::reset() |
5754 | { |
5755 | DBUG_ENTER("spider_handlersocket_handler::reset" ); |
5756 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5757 | DBUG_RETURN(0); |
5758 | } |
5759 | |
5760 | int spider_handlersocket_handler::sts_mode_exchange( |
5761 | int sts_mode |
5762 | ) { |
5763 | DBUG_ENTER("spider_handlersocket_handler::sts_mode_exchange" ); |
5764 | DBUG_PRINT("info" ,("spider sts_mode=%d" , sts_mode)); |
5765 | DBUG_RETURN(sts_mode); |
5766 | } |
5767 | |
5768 | int spider_handlersocket_handler::show_table_status( |
5769 | int link_idx, |
5770 | int sts_mode, |
5771 | uint flag |
5772 | ) { |
5773 | spider_db_handlersocket_result res(NULL); |
5774 | SPIDER_SHARE *share = spider->share; |
5775 | ulonglong auto_increment_value = 0; |
5776 | DBUG_ENTER("spider_handlersocket_show_table_status" ); |
5777 | res.fetch_table_status( |
5778 | sts_mode, |
5779 | share->records, |
5780 | share->mean_rec_length, |
5781 | share->data_file_length, |
5782 | share->max_data_file_length, |
5783 | share->index_file_length, |
5784 | auto_increment_value, |
5785 | share->create_time, |
5786 | share->update_time, |
5787 | share->check_time |
5788 | ); |
5789 | if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value) |
5790 | { |
5791 | share->lgtm_tblhnd_share->auto_increment_value = auto_increment_value; |
5792 | DBUG_PRINT("info" ,("spider auto_increment_value=%llu" , |
5793 | share->lgtm_tblhnd_share->auto_increment_value)); |
5794 | } |
5795 | DBUG_RETURN(0); |
5796 | } |
5797 | |
5798 | int spider_handlersocket_handler::crd_mode_exchange( |
5799 | int crd_mode |
5800 | ) { |
5801 | DBUG_ENTER("spider_handlersocket_handler::crd_mode_exchange" ); |
5802 | DBUG_PRINT("info" ,("spider crd_mode=%d" , crd_mode)); |
5803 | DBUG_RETURN(crd_mode); |
5804 | } |
5805 | |
5806 | int spider_handlersocket_handler::show_index( |
5807 | int link_idx, |
5808 | int crd_mode |
5809 | ) { |
5810 | DBUG_ENTER("spider_handlersocket_handler::show_index" ); |
5811 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5812 | DBUG_ASSERT(0); |
5813 | DBUG_RETURN(0); |
5814 | } |
5815 | |
5816 | int spider_handlersocket_handler::show_records( |
5817 | int link_idx |
5818 | ) { |
5819 | DBUG_ENTER("spider_handlersocket_handler::show_records" ); |
5820 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5821 | DBUG_ASSERT(0); |
5822 | DBUG_RETURN(0); |
5823 | } |
5824 | |
5825 | int spider_handlersocket_handler::show_last_insert_id( |
5826 | int link_idx, |
5827 | ulonglong &last_insert_id |
5828 | ) { |
5829 | DBUG_ENTER("spider_handlersocket_handler::show_last_insert_id" ); |
5830 | last_insert_id = 0; |
5831 | DBUG_RETURN(0); |
5832 | } |
5833 | |
5834 | ha_rows spider_handlersocket_handler::explain_select( |
5835 | key_range *start_key, |
5836 | key_range *end_key, |
5837 | int link_idx |
5838 | ) { |
5839 | DBUG_ENTER("spider_handlersocket_handler::explain_select" ); |
5840 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5841 | DBUG_ASSERT(0); |
5842 | DBUG_RETURN(0); |
5843 | } |
5844 | |
5845 | int spider_handlersocket_handler::lock_tables( |
5846 | int link_idx |
5847 | ) { |
5848 | DBUG_ENTER("spider_handlersocket_handler::lock_tables" ); |
5849 | DBUG_ASSERT(0); |
5850 | DBUG_RETURN(0); |
5851 | } |
5852 | |
5853 | int spider_handlersocket_handler::unlock_tables( |
5854 | int link_idx |
5855 | ) { |
5856 | DBUG_ENTER("spider_handlersocket_handler::unlock_tables" ); |
5857 | DBUG_ASSERT(0); |
5858 | DBUG_RETURN(0); |
5859 | } |
5860 | |
5861 | int spider_handlersocket_handler::disable_keys( |
5862 | SPIDER_CONN *conn, |
5863 | int link_idx |
5864 | ) { |
5865 | DBUG_ENTER("spider_handlersocket_handler::disable_keys" ); |
5866 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5867 | DBUG_ASSERT(0); |
5868 | DBUG_RETURN(0); |
5869 | } |
5870 | |
5871 | int spider_handlersocket_handler::enable_keys( |
5872 | SPIDER_CONN *conn, |
5873 | int link_idx |
5874 | ) { |
5875 | DBUG_ENTER("spider_handlersocket_handler::enable_keys" ); |
5876 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5877 | DBUG_ASSERT(0); |
5878 | DBUG_RETURN(0); |
5879 | } |
5880 | |
5881 | int spider_handlersocket_handler::check_table( |
5882 | SPIDER_CONN *conn, |
5883 | int link_idx, |
5884 | HA_CHECK_OPT* check_opt |
5885 | ) { |
5886 | DBUG_ENTER("spider_handlersocket_handler::check_table" ); |
5887 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5888 | DBUG_ASSERT(0); |
5889 | DBUG_RETURN(0); |
5890 | } |
5891 | |
5892 | int spider_handlersocket_handler::repair_table( |
5893 | SPIDER_CONN *conn, |
5894 | int link_idx, |
5895 | HA_CHECK_OPT* check_opt |
5896 | ) { |
5897 | DBUG_ENTER("spider_handlersocket_handler::repair_table" ); |
5898 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5899 | DBUG_ASSERT(0); |
5900 | DBUG_RETURN(0); |
5901 | } |
5902 | |
5903 | int spider_handlersocket_handler::analyze_table( |
5904 | SPIDER_CONN *conn, |
5905 | int link_idx |
5906 | ) { |
5907 | DBUG_ENTER("spider_handlersocket_handler::analyze_table" ); |
5908 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5909 | DBUG_ASSERT(0); |
5910 | DBUG_RETURN(0); |
5911 | } |
5912 | |
5913 | int spider_handlersocket_handler::optimize_table( |
5914 | SPIDER_CONN *conn, |
5915 | int link_idx |
5916 | ) { |
5917 | DBUG_ENTER("spider_handlersocket_handler::optimize_table" ); |
5918 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5919 | DBUG_ASSERT(0); |
5920 | DBUG_RETURN(0); |
5921 | } |
5922 | |
5923 | int spider_handlersocket_handler::flush_tables( |
5924 | SPIDER_CONN *conn, |
5925 | int link_idx, |
5926 | bool lock |
5927 | ) { |
5928 | DBUG_ENTER("spider_handlersocket_handler::flush_tables" ); |
5929 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5930 | DBUG_ASSERT(0); |
5931 | DBUG_RETURN(0); |
5932 | } |
5933 | |
5934 | int spider_handlersocket_handler::flush_logs( |
5935 | SPIDER_CONN *conn, |
5936 | int link_idx |
5937 | ) { |
5938 | DBUG_ENTER("spider_handlersocket_handler::flush_logs" ); |
5939 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5940 | DBUG_ASSERT(0); |
5941 | DBUG_RETURN(0); |
5942 | } |
5943 | |
5944 | int spider_handlersocket_handler::insert_opened_handler( |
5945 | SPIDER_CONN *conn, |
5946 | int link_idx |
5947 | ) { |
5948 | spider_db_handlersocket *db_conn = (spider_db_handlersocket *) conn->db_conn; |
5949 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash = &link_for_hash[link_idx]; |
5950 | DBUG_ASSERT(tmp_link_for_hash->spider == spider); |
5951 | DBUG_ASSERT(tmp_link_for_hash->link_idx == link_idx); |
5952 | uint old_elements = db_conn->handler_open_array.max_element; |
5953 | DBUG_ENTER("spider_handlersocket_handler::insert_opened_handler" ); |
5954 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5955 | if (insert_dynamic(&db_conn->handler_open_array, |
5956 | (uchar*) &tmp_link_for_hash)) |
5957 | { |
5958 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
5959 | } |
5960 | if (db_conn->handler_open_array.max_element > old_elements) |
5961 | { |
5962 | spider_alloc_calc_mem(spider_current_trx, |
5963 | db_conn->handler_open_array, |
5964 | (db_conn->handler_open_array.max_element - old_elements) * |
5965 | db_conn->handler_open_array.size_of_element); |
5966 | } |
5967 | DBUG_RETURN(0); |
5968 | } |
5969 | |
5970 | int spider_handlersocket_handler::delete_opened_handler( |
5971 | SPIDER_CONN *conn, |
5972 | int link_idx |
5973 | ) { |
5974 | spider_db_handlersocket *db_conn = (spider_db_handlersocket *) conn->db_conn; |
5975 | uint roop_count, elements = db_conn->handler_open_array.elements; |
5976 | SPIDER_LINK_FOR_HASH *tmp_link_for_hash; |
5977 | DBUG_ENTER("spider_handlersocket_handler::delete_opened_handler" ); |
5978 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
5979 | for (roop_count = 0; roop_count < elements; roop_count++) |
5980 | { |
5981 | get_dynamic(&db_conn->handler_open_array, (uchar *) &tmp_link_for_hash, |
5982 | roop_count); |
5983 | if (tmp_link_for_hash == &link_for_hash[link_idx]) |
5984 | { |
5985 | delete_dynamic_element(&db_conn->handler_open_array, roop_count); |
5986 | break; |
5987 | } |
5988 | } |
5989 | DBUG_ASSERT(roop_count < elements); |
5990 | DBUG_RETURN(0); |
5991 | } |
5992 | |
5993 | int spider_handlersocket_handler::sync_from_clone_source( |
5994 | spider_db_handler *dbton_hdl |
5995 | ) { |
5996 | spider_handlersocket_handler *hs_hdl = |
5997 | (spider_handlersocket_handler *) dbton_hdl; |
5998 | DBUG_ENTER("spider_handlersocket_handler::sync_from_clone_source" ); |
5999 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6000 | hs_strs_pos = hs_hdl->hs_strs_pos; |
6001 | DBUG_RETURN(0); |
6002 | } |
6003 | |
6004 | bool spider_handlersocket_handler::support_use_handler( |
6005 | int use_handler |
6006 | ) { |
6007 | DBUG_ENTER("spider_handlersocket_handler::support_use_handler" ); |
6008 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6009 | DBUG_RETURN(TRUE); |
6010 | } |
6011 | |
6012 | void spider_handlersocket_handler::minimum_select_bitmap_create() |
6013 | { |
6014 | TABLE *table = spider->get_table(); |
6015 | Field **field_p; |
6016 | DBUG_ENTER("spider_handlersocket_handler::minimum_select_bitmap_create" ); |
6017 | memset(minimum_select_bitmap, 0, no_bytes_in_map(table->read_set)); |
6018 | if ( |
6019 | spider->use_index_merge || |
6020 | #ifdef HA_CAN_BULK_ACCESS |
6021 | (spider->is_clone && !spider->is_bulk_access_clone) |
6022 | #else |
6023 | spider->is_clone |
6024 | #endif |
6025 | ) { |
6026 | /* need preparing for cmp_ref */ |
6027 | TABLE_SHARE *table_share = table->s; |
6028 | if ( |
6029 | table_share->primary_key == MAX_KEY |
6030 | ) { |
6031 | /* need all columns */ |
6032 | memset(minimum_select_bitmap, 0xFF, no_bytes_in_map(table->read_set)); |
6033 | DBUG_VOID_RETURN; |
6034 | } else { |
6035 | /* need primary key columns */ |
6036 | uint roop_count; |
6037 | KEY *key_info; |
6038 | KEY_PART_INFO *key_part; |
6039 | Field *field; |
6040 | key_info = &table_share->key_info[table_share->primary_key]; |
6041 | key_part = key_info->key_part; |
6042 | for (roop_count = 0; |
6043 | roop_count < spider_user_defined_key_parts(key_info); |
6044 | roop_count++) |
6045 | { |
6046 | field = key_part[roop_count].field; |
6047 | spider_set_bit(minimum_select_bitmap, field->field_index); |
6048 | } |
6049 | } |
6050 | } |
6051 | for (field_p = table->field; *field_p; field_p++) |
6052 | { |
6053 | uint field_index = (*field_p)->field_index; |
6054 | if ( |
6055 | spider_bit_is_set(spider->searched_bitmap, field_index) | |
6056 | bitmap_is_set(table->read_set, field_index) | |
6057 | bitmap_is_set(table->write_set, field_index) |
6058 | ) { |
6059 | spider_set_bit(minimum_select_bitmap, field_index); |
6060 | } |
6061 | } |
6062 | DBUG_VOID_RETURN; |
6063 | } |
6064 | |
6065 | bool spider_handlersocket_handler::minimum_select_bit_is_set( |
6066 | uint field_index |
6067 | ) { |
6068 | DBUG_ENTER("spider_handlersocket_handler::minimum_select_bit_is_set" ); |
6069 | DBUG_PRINT("info" ,("spider field_index=%u" , field_index)); |
6070 | DBUG_PRINT("info" ,("spider minimum_select_bitmap=%s" , |
6071 | spider_bit_is_set(minimum_select_bitmap, field_index) ? |
6072 | "TRUE" : "FALSE" )); |
6073 | DBUG_RETURN(spider_bit_is_set(minimum_select_bitmap, field_index)); |
6074 | } |
6075 | |
6076 | void spider_handlersocket_handler::copy_minimum_select_bitmap( |
6077 | uchar *bitmap |
6078 | ) { |
6079 | int roop_count; |
6080 | TABLE *table = spider->get_table(); |
6081 | DBUG_ENTER("spider_handlersocket_handler::copy_minimum_select_bitmap" ); |
6082 | for (roop_count = 0; |
6083 | roop_count < (int) ((table->s->fields + 7) / 8); |
6084 | roop_count++) |
6085 | { |
6086 | bitmap[roop_count] = |
6087 | minimum_select_bitmap[roop_count]; |
6088 | DBUG_PRINT("info" ,("spider roop_count=%d" , roop_count)); |
6089 | DBUG_PRINT("info" ,("spider bitmap=%d" , |
6090 | bitmap[roop_count])); |
6091 | } |
6092 | DBUG_VOID_RETURN; |
6093 | } |
6094 | |
6095 | int spider_handlersocket_handler::init_union_table_name_pos() |
6096 | { |
6097 | DBUG_ENTER("spider_handlersocket_handler::init_union_table_name_pos" ); |
6098 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6099 | DBUG_ASSERT(0); |
6100 | DBUG_RETURN(0); |
6101 | } |
6102 | |
6103 | int spider_handlersocket_handler::set_union_table_name_pos() |
6104 | { |
6105 | DBUG_ENTER("spider_handlersocket_handler::set_union_table_name_pos" ); |
6106 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6107 | DBUG_ASSERT(0); |
6108 | DBUG_RETURN(0); |
6109 | } |
6110 | |
6111 | int spider_handlersocket_handler::reset_union_table_name( |
6112 | spider_string *str, |
6113 | int link_idx, |
6114 | ulong sql_type |
6115 | ) { |
6116 | DBUG_ENTER("spider_handlersocket_handler::reset_union_table_name" ); |
6117 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6118 | DBUG_ASSERT(0); |
6119 | DBUG_RETURN(0); |
6120 | } |
6121 | |
6122 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
6123 | int spider_handlersocket_handler::append_list_item_select_part( |
6124 | List<Item> *select, |
6125 | const char *alias, |
6126 | uint alias_length, |
6127 | bool use_fields, |
6128 | spider_fields *fields, |
6129 | ulong sql_type |
6130 | ) { |
6131 | DBUG_ENTER("spider_handlersocket_handler::append_list_item_select_part" ); |
6132 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6133 | DBUG_ASSERT(0); |
6134 | DBUG_RETURN(0); |
6135 | } |
6136 | |
6137 | int spider_handlersocket_handler::append_from_and_tables_part( |
6138 | spider_fields *fields, |
6139 | ulong sql_type |
6140 | ) { |
6141 | DBUG_ENTER("spider_handlersocket_handler::append_from_and_tables_part" ); |
6142 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6143 | DBUG_ASSERT(0); |
6144 | DBUG_RETURN(0); |
6145 | } |
6146 | |
6147 | int spider_handlersocket_handler::reappend_tables_part( |
6148 | spider_fields *fields, |
6149 | ulong sql_type |
6150 | ) { |
6151 | DBUG_ENTER("spider_handlersocket_handler::reappend_tables_part" ); |
6152 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6153 | DBUG_ASSERT(0); |
6154 | DBUG_RETURN(0); |
6155 | } |
6156 | |
6157 | int spider_handlersocket_handler::append_where_part( |
6158 | ulong sql_type |
6159 | ) { |
6160 | DBUG_ENTER("spider_handlersocket_handler::append_where_part" ); |
6161 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6162 | DBUG_ASSERT(0); |
6163 | DBUG_RETURN(0); |
6164 | } |
6165 | |
6166 | int spider_handlersocket_handler::append_having_part( |
6167 | ulong sql_type |
6168 | ) { |
6169 | DBUG_ENTER("spider_handlersocket_handler::append_having_part" ); |
6170 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6171 | DBUG_ASSERT(0); |
6172 | DBUG_RETURN(0); |
6173 | } |
6174 | |
6175 | int spider_handlersocket_handler::append_item_type_part( |
6176 | Item *item, |
6177 | const char *alias, |
6178 | uint alias_length, |
6179 | bool use_fields, |
6180 | spider_fields *fields, |
6181 | ulong sql_type |
6182 | ) { |
6183 | DBUG_ENTER("spider_handlersocket_handler::append_item_type_part" ); |
6184 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6185 | DBUG_ASSERT(0); |
6186 | DBUG_RETURN(0); |
6187 | } |
6188 | |
6189 | int spider_handlersocket_handler::append_group_by_part( |
6190 | ORDER *order, |
6191 | const char *alias, |
6192 | uint alias_length, |
6193 | bool use_fields, |
6194 | spider_fields *fields, |
6195 | ulong sql_type |
6196 | ) { |
6197 | DBUG_ENTER("spider_handlersocket_handler::append_group_by_part" ); |
6198 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6199 | DBUG_ASSERT(0); |
6200 | DBUG_RETURN(0); |
6201 | } |
6202 | |
6203 | int spider_handlersocket_handler::append_order_by_part( |
6204 | ORDER *order, |
6205 | const char *alias, |
6206 | uint alias_length, |
6207 | bool use_fields, |
6208 | spider_fields *fields, |
6209 | ulong sql_type |
6210 | ) { |
6211 | DBUG_ENTER("spider_handlersocket_handler::append_order_by_part" ); |
6212 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
6213 | DBUG_ASSERT(0); |
6214 | DBUG_RETURN(0); |
6215 | } |
6216 | #endif |
6217 | #endif |
6218 | |