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 | class spider_db_mysql_util: public spider_db_util |
17 | { |
18 | public: |
19 | spider_db_mysql_util(); |
20 | ~spider_db_mysql_util(); |
21 | int append_name( |
22 | spider_string *str, |
23 | const char *name, |
24 | uint name_length |
25 | ); |
26 | int append_name_with_charset( |
27 | spider_string *str, |
28 | const char *name, |
29 | uint name_length, |
30 | CHARSET_INFO *name_charset |
31 | ); |
32 | bool is_name_quote( |
33 | const char head_code |
34 | ); |
35 | int append_escaped_name_quote( |
36 | spider_string *str |
37 | ); |
38 | int append_column_value( |
39 | ha_spider *spider, |
40 | spider_string *str, |
41 | Field *field, |
42 | const uchar *new_ptr, |
43 | CHARSET_INFO *access_charset |
44 | ); |
45 | int append_from_with_alias( |
46 | spider_string *str, |
47 | const char **table_names, |
48 | uint *table_name_lengths, |
49 | const char **table_aliases, |
50 | uint *table_alias_lengths, |
51 | uint table_count, |
52 | int *table_name_pos, |
53 | bool over_write |
54 | ); |
55 | int append_trx_isolation( |
56 | spider_string *str, |
57 | int trx_isolation |
58 | ); |
59 | int append_autocommit( |
60 | spider_string *str, |
61 | bool autocommit |
62 | ); |
63 | int append_sql_log_off( |
64 | spider_string *str, |
65 | bool sql_log_off |
66 | ); |
67 | int append_time_zone( |
68 | spider_string *str, |
69 | Time_zone *time_zone |
70 | ); |
71 | int append_start_transaction( |
72 | spider_string *str |
73 | ); |
74 | int append_xa_start( |
75 | spider_string *str, |
76 | XID *xid |
77 | ); |
78 | int append_lock_table_head( |
79 | spider_string *str |
80 | ); |
81 | int append_lock_table_body( |
82 | spider_string *str, |
83 | const char *db_name, |
84 | uint db_name_length, |
85 | CHARSET_INFO *db_name_charset, |
86 | const char *table_name, |
87 | uint table_name_length, |
88 | CHARSET_INFO *table_name_charset, |
89 | int lock_type |
90 | ); |
91 | int append_lock_table_tail( |
92 | spider_string *str |
93 | ); |
94 | int append_unlock_table( |
95 | spider_string *str |
96 | ); |
97 | int open_item_func( |
98 | Item_func *item_func, |
99 | ha_spider *spider, |
100 | spider_string *str, |
101 | const char *alias, |
102 | uint alias_length, |
103 | bool use_fields, |
104 | spider_fields *fields |
105 | ); |
106 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
107 | int open_item_sum_func( |
108 | Item_sum *item_sum, |
109 | ha_spider *spider, |
110 | spider_string *str, |
111 | const char *alias, |
112 | uint alias_length, |
113 | bool use_fields, |
114 | spider_fields *fields |
115 | ); |
116 | #endif |
117 | int append_escaped_util( |
118 | spider_string *to, |
119 | String *from |
120 | ); |
121 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
122 | int append_from_and_tables( |
123 | spider_fields *fields, |
124 | spider_string *str |
125 | ); |
126 | int reappend_tables( |
127 | spider_fields *fields, |
128 | SPIDER_LINK_IDX_CHAIN *link_idx_chain, |
129 | spider_string *str |
130 | ); |
131 | int append_where( |
132 | spider_string *str |
133 | ); |
134 | int append_having( |
135 | spider_string *str |
136 | ); |
137 | #endif |
138 | }; |
139 | |
140 | class spider_db_mysql_row: public spider_db_row |
141 | { |
142 | public: |
143 | MYSQL_ROW row; |
144 | MYSQL_ROW row_first; |
145 | ulong *lengths; |
146 | ulong *lengths_first; |
147 | uint field_count; |
148 | bool cloned; |
149 | spider_db_mysql_row(); |
150 | ~spider_db_mysql_row(); |
151 | int store_to_field( |
152 | Field *field, |
153 | CHARSET_INFO *access_charset |
154 | ); |
155 | int append_to_str( |
156 | spider_string *str |
157 | ); |
158 | int append_escaped_to_str( |
159 | spider_string *str, |
160 | uint dbton_id |
161 | ); |
162 | void first(); |
163 | void next(); |
164 | bool is_null(); |
165 | int val_int(); |
166 | double val_real(); |
167 | my_decimal *val_decimal( |
168 | my_decimal *decimal_value, |
169 | CHARSET_INFO *access_charset |
170 | ); |
171 | SPIDER_DB_ROW *clone(); |
172 | int store_to_tmp_table( |
173 | TABLE *tmp_table, |
174 | spider_string *str |
175 | ); |
176 | }; |
177 | |
178 | class spider_db_mysql_result: public spider_db_result |
179 | { |
180 | public: |
181 | MYSQL_RES *db_result; |
182 | spider_db_mysql_row row; |
183 | MYSQL_ROW_OFFSET first_row; |
184 | int store_error_num; |
185 | spider_db_mysql_result(SPIDER_DB_CONN *in_db_conn); |
186 | ~spider_db_mysql_result(); |
187 | bool has_result(); |
188 | void free_result(); |
189 | SPIDER_DB_ROW *current_row(); |
190 | SPIDER_DB_ROW *fetch_row(); |
191 | SPIDER_DB_ROW *fetch_row_from_result_buffer( |
192 | spider_db_result_buffer *spider_res_buf |
193 | ); |
194 | SPIDER_DB_ROW *fetch_row_from_tmp_table( |
195 | TABLE *tmp_table |
196 | ); |
197 | int fetch_table_status( |
198 | int mode, |
199 | ha_rows &records, |
200 | ulong &mean_rec_length, |
201 | ulonglong &data_file_length, |
202 | ulonglong &max_data_file_length, |
203 | ulonglong &index_file_length, |
204 | ulonglong &auto_increment_value, |
205 | time_t &create_time, |
206 | time_t &update_time, |
207 | time_t &check_time |
208 | ); |
209 | int fetch_table_records( |
210 | int mode, |
211 | ha_rows &records |
212 | ); |
213 | int fetch_table_cardinality( |
214 | int mode, |
215 | TABLE *table, |
216 | longlong *cardinality, |
217 | uchar *cardinality_upd, |
218 | int bitmap_size |
219 | ); |
220 | int fetch_table_mon_status( |
221 | int &status |
222 | ); |
223 | int fetch_show_master_status( |
224 | const char **binlog_file_name, |
225 | const char **binlog_pos |
226 | ); |
227 | int fetch_select_binlog_gtid_pos( |
228 | const char **gtid_pos |
229 | ); |
230 | longlong num_rows(); |
231 | uint num_fields(); |
232 | void move_to_pos( |
233 | longlong pos |
234 | ); |
235 | int get_errno(); |
236 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
237 | int fetch_columns_for_discover_table_structure( |
238 | spider_string *str, |
239 | CHARSET_INFO *access_charset |
240 | ); |
241 | int fetch_index_for_discover_table_structure( |
242 | spider_string *str, |
243 | CHARSET_INFO *access_charset |
244 | ); |
245 | int fetch_table_for_discover_table_structure( |
246 | spider_string *str, |
247 | SPIDER_SHARE *spider_share, |
248 | CHARSET_INFO *access_charset |
249 | ); |
250 | #endif |
251 | }; |
252 | |
253 | class spider_db_mysql: public spider_db_conn |
254 | { |
255 | int stored_error; |
256 | public: |
257 | MYSQL *db_conn; |
258 | HASH lock_table_hash; |
259 | bool lock_table_hash_inited; |
260 | uint lock_table_hash_id; |
261 | const char *lock_table_hash_func_name; |
262 | const char *lock_table_hash_file_name; |
263 | ulong lock_table_hash_line_no; |
264 | DYNAMIC_ARRAY handler_open_array; |
265 | bool handler_open_array_inited; |
266 | uint handler_open_array_id; |
267 | const char *handler_open_array_func_name; |
268 | const char *handler_open_array_file_name; |
269 | ulong handler_open_array_line_no; |
270 | spider_db_mysql( |
271 | SPIDER_CONN *conn |
272 | ); |
273 | ~spider_db_mysql(); |
274 | int init(); |
275 | bool is_connected(); |
276 | void bg_connect(); |
277 | int connect( |
278 | char *tgt_host, |
279 | char *tgt_username, |
280 | char *tgt_password, |
281 | long tgt_port, |
282 | char *tgt_socket, |
283 | char *server_name, |
284 | int connect_retry_count, |
285 | longlong connect_retry_interval |
286 | ); |
287 | int ping(); |
288 | void bg_disconnect(); |
289 | void disconnect(); |
290 | int set_net_timeout(); |
291 | int exec_query( |
292 | const char *query, |
293 | uint length, |
294 | int quick_mode |
295 | ); |
296 | int get_errno(); |
297 | const char *get_error(); |
298 | bool is_server_gone_error( |
299 | int error_num |
300 | ); |
301 | bool is_dup_entry_error( |
302 | int error_num |
303 | ); |
304 | bool is_xa_nota_error( |
305 | int error_num |
306 | ); |
307 | void print_warnings( |
308 | struct tm *l_time |
309 | ); |
310 | spider_db_result *store_result( |
311 | spider_db_result_buffer **spider_res_buf, |
312 | st_spider_db_request_key *request_key, |
313 | int *error_num |
314 | ); |
315 | spider_db_result *use_result( |
316 | st_spider_db_request_key *request_key, |
317 | int *error_num |
318 | ); |
319 | int next_result(); |
320 | uint affected_rows(); |
321 | ulonglong last_insert_id(); |
322 | int set_character_set( |
323 | const char *csname |
324 | ); |
325 | int select_db( |
326 | const char *dbname |
327 | ); |
328 | int consistent_snapshot( |
329 | int *need_mon |
330 | ); |
331 | bool trx_start_in_bulk_sql(); |
332 | int start_transaction( |
333 | int *need_mon |
334 | ); |
335 | int commit( |
336 | int *need_mon |
337 | ); |
338 | int rollback( |
339 | int *need_mon |
340 | ); |
341 | bool xa_start_in_bulk_sql(); |
342 | int xa_start( |
343 | XID *xid, |
344 | int *need_mon |
345 | ); |
346 | int xa_end( |
347 | XID *xid, |
348 | int *need_mon |
349 | ); |
350 | int xa_prepare( |
351 | XID *xid, |
352 | int *need_mon |
353 | ); |
354 | int xa_commit( |
355 | XID *xid, |
356 | int *need_mon |
357 | ); |
358 | int xa_rollback( |
359 | XID *xid, |
360 | int *need_mon |
361 | ); |
362 | bool set_trx_isolation_in_bulk_sql(); |
363 | int set_trx_isolation( |
364 | int trx_isolation, |
365 | int *need_mon |
366 | ); |
367 | bool set_autocommit_in_bulk_sql(); |
368 | int set_autocommit( |
369 | bool autocommit, |
370 | int *need_mon |
371 | ); |
372 | bool set_sql_log_off_in_bulk_sql(); |
373 | int set_sql_log_off( |
374 | bool sql_log_off, |
375 | int *need_mon |
376 | ); |
377 | bool set_time_zone_in_bulk_sql(); |
378 | int set_time_zone( |
379 | Time_zone *time_zone, |
380 | int *need_mon |
381 | ); |
382 | int exec_simple_sql_with_result( |
383 | SPIDER_TRX *trx, |
384 | SPIDER_SHARE *share, |
385 | const char *sql, |
386 | uint sql_length, |
387 | int all_link_idx, |
388 | int *need_mon, |
389 | SPIDER_DB_RESULT **res |
390 | ); |
391 | int show_master_status( |
392 | SPIDER_TRX *trx, |
393 | SPIDER_SHARE *share, |
394 | int all_link_idx, |
395 | int *need_mon, |
396 | TABLE *table, |
397 | spider_string *str, |
398 | int mode, |
399 | SPIDER_DB_RESULT **res1, |
400 | SPIDER_DB_RESULT **res2 |
401 | ); |
402 | int select_binlog_gtid_pos( |
403 | SPIDER_TRX *trx, |
404 | SPIDER_SHARE *share, |
405 | int all_link_idx, |
406 | int *need_mon, |
407 | TABLE *table, |
408 | spider_string *str, |
409 | const char *binlog_file_name, |
410 | uint binlog_file_name_length, |
411 | const char *binlog_pos, |
412 | uint binlog_pos_length, |
413 | SPIDER_DB_RESULT **res |
414 | ); |
415 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
416 | int append_sql( |
417 | char *sql, |
418 | ulong sql_length, |
419 | st_spider_db_request_key *request_key |
420 | ); |
421 | int append_open_handler( |
422 | uint handler_id, |
423 | const char *db_name, |
424 | const char *table_name, |
425 | const char *index_name, |
426 | const char *sql, |
427 | st_spider_db_request_key *request_key |
428 | ); |
429 | int append_select( |
430 | uint handler_id, |
431 | spider_string *sql, |
432 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
433 | int limit, |
434 | int skip, |
435 | st_spider_db_request_key *request_key |
436 | ); |
437 | int append_insert( |
438 | uint handler_id, |
439 | SPIDER_DB_HS_STRING_REF_BUFFER *upds, |
440 | st_spider_db_request_key *request_key |
441 | ); |
442 | int append_update( |
443 | uint handler_id, |
444 | spider_string *sql, |
445 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
446 | SPIDER_DB_HS_STRING_REF_BUFFER *upds, |
447 | int limit, |
448 | int skip, |
449 | bool increment, |
450 | bool decrement, |
451 | st_spider_db_request_key *request_key |
452 | ); |
453 | int append_delete( |
454 | uint handler_id, |
455 | spider_string *sql, |
456 | SPIDER_DB_HS_STRING_REF_BUFFER *keys, |
457 | int limit, |
458 | int skip, |
459 | st_spider_db_request_key *request_key |
460 | ); |
461 | void reset_request_queue(); |
462 | #endif |
463 | size_t escape_string( |
464 | char *to, |
465 | const char *from, |
466 | size_t from_length |
467 | ); |
468 | bool have_lock_table_list(); |
469 | int append_lock_tables( |
470 | spider_string *str |
471 | ); |
472 | int append_unlock_tables( |
473 | spider_string *str |
474 | ); |
475 | uint get_lock_table_hash_count(); |
476 | void reset_lock_table_hash(); |
477 | uint get_opened_handler_count(); |
478 | void reset_opened_handler(); |
479 | void set_dup_key_idx( |
480 | ha_spider *spider, |
481 | int link_idx |
482 | ); |
483 | bool cmp_request_key_to_snd( |
484 | st_spider_db_request_key *request_key |
485 | ); |
486 | }; |
487 | |
488 | class spider_mysql_share: public spider_db_share |
489 | { |
490 | public: |
491 | spider_string *table_select; |
492 | int table_select_pos; |
493 | spider_string *key_select; |
494 | int *key_select_pos; |
495 | spider_string *key_hint; |
496 | spider_string *show_table_status; |
497 | spider_string *show_records; |
498 | spider_string *show_index; |
499 | spider_string *table_names_str; |
500 | spider_string *db_names_str; |
501 | spider_string *db_table_str; |
502 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
503 | my_hash_value_type *db_table_str_hash_value; |
504 | #endif |
505 | uint table_nm_max_length; |
506 | uint db_nm_max_length; |
507 | spider_string *column_name_str; |
508 | bool same_db_table_name; |
509 | int first_all_link_idx; |
510 | |
511 | spider_mysql_share( |
512 | st_spider_share *share |
513 | ); |
514 | ~spider_mysql_share(); |
515 | int init(); |
516 | uint get_column_name_length( |
517 | uint field_index |
518 | ); |
519 | int append_column_name( |
520 | spider_string *str, |
521 | uint field_index |
522 | ); |
523 | int append_column_name_with_alias( |
524 | spider_string *str, |
525 | uint field_index, |
526 | const char *alias, |
527 | uint alias_length |
528 | ); |
529 | int append_table_name( |
530 | spider_string *str, |
531 | int all_link_idx |
532 | ); |
533 | int append_table_name_with_adjusting( |
534 | spider_string *str, |
535 | int all_link_idx |
536 | ); |
537 | int append_from_with_adjusted_table_name( |
538 | spider_string *str, |
539 | int *table_name_pos |
540 | ); |
541 | bool need_change_db_table_name(); |
542 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
543 | int discover_table_structure( |
544 | SPIDER_TRX *trx, |
545 | SPIDER_SHARE *spider_share, |
546 | spider_string *str |
547 | ); |
548 | #endif |
549 | private: |
550 | int create_table_names_str(); |
551 | void free_table_names_str(); |
552 | int create_column_name_str(); |
553 | void free_column_name_str(); |
554 | int convert_key_hint_str(); |
555 | int append_show_table_status(); |
556 | void free_show_table_status(); |
557 | int append_show_records(); |
558 | void free_show_records(); |
559 | int append_show_index(); |
560 | void free_show_index(); |
561 | int append_table_select(); |
562 | int append_key_select( |
563 | uint idx |
564 | ); |
565 | }; |
566 | |
567 | class spider_mysql_handler: public spider_db_handler |
568 | { |
569 | spider_string sql; |
570 | spider_string sql_part; |
571 | spider_string sql_part2; |
572 | spider_string ha_sql; |
573 | int where_pos; |
574 | int order_pos; |
575 | int limit_pos; |
576 | public: |
577 | int table_name_pos; |
578 | private: |
579 | int ha_read_pos; |
580 | int ha_next_pos; |
581 | int ha_where_pos; |
582 | int ha_limit_pos; |
583 | int ha_table_name_pos; |
584 | uint ha_sql_handler_id; |
585 | spider_string insert_sql; |
586 | int insert_pos; |
587 | int insert_table_name_pos; |
588 | spider_string update_sql; |
589 | TABLE *upd_tmp_tbl; |
590 | TMP_TABLE_PARAM upd_tmp_tbl_prm; |
591 | spider_string tmp_sql; |
592 | int tmp_sql_pos1; /* drop db nm pos at tmp_table_join */ |
593 | int tmp_sql_pos2; /* create db nm pos at tmp_table_join */ |
594 | int tmp_sql_pos3; /* insert db nm pos at tmp_table_join */ |
595 | int tmp_sql_pos4; /* insert val pos at tmp_table_join */ |
596 | int tmp_sql_pos5; /* end of drop tbl at tmp_table_join */ |
597 | spider_string dup_update_sql; |
598 | spider_string *exec_sql; |
599 | spider_string *exec_insert_sql; |
600 | spider_string *exec_update_sql; |
601 | spider_string *exec_tmp_sql; |
602 | spider_string *exec_ha_sql; |
603 | bool reading_from_bulk_tmp_table; |
604 | bool filled_up; |
605 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
606 | SPIDER_DB_HS_STRING_REF_BUFFER hs_upds; |
607 | #endif |
608 | SPIDER_INT_HLD *union_table_name_pos_first; |
609 | SPIDER_INT_HLD *union_table_name_pos_current; |
610 | public: |
611 | spider_mysql_share *mysql_share; |
612 | SPIDER_LINK_FOR_HASH *link_for_hash; |
613 | uchar *minimum_select_bitmap; |
614 | spider_mysql_handler( |
615 | ha_spider *spider, |
616 | spider_mysql_share *share |
617 | ); |
618 | ~spider_mysql_handler(); |
619 | int init(); |
620 | int append_index_hint( |
621 | spider_string *str, |
622 | int link_idx, |
623 | ulong sql_type |
624 | ); |
625 | int append_table_name_with_adjusting( |
626 | spider_string *str, |
627 | int link_idx, |
628 | ulong sql_type |
629 | ); |
630 | int append_key_column_types( |
631 | const key_range *start_key, |
632 | spider_string *str |
633 | ); |
634 | int append_key_join_columns_for_bka( |
635 | const key_range *start_key, |
636 | spider_string *str, |
637 | const char **table_aliases, |
638 | uint *table_alias_lengths |
639 | ); |
640 | int append_tmp_table_and_sql_for_bka( |
641 | const key_range *start_key |
642 | ); |
643 | int reuse_tmp_table_and_sql_for_bka(); |
644 | void create_tmp_bka_table_name( |
645 | char *tmp_table_name, |
646 | int *tmp_table_name_length, |
647 | int link_idx |
648 | ); |
649 | int append_create_tmp_bka_table( |
650 | const key_range *start_key, |
651 | spider_string *str, |
652 | char *tmp_table_name, |
653 | int tmp_table_name_length, |
654 | int *db_name_pos, |
655 | CHARSET_INFO *table_charset |
656 | ); |
657 | int append_drop_tmp_bka_table( |
658 | spider_string *str, |
659 | char *tmp_table_name, |
660 | int tmp_table_name_length, |
661 | int *db_name_pos, |
662 | int *drop_table_end_pos, |
663 | bool with_semicolon |
664 | ); |
665 | int append_insert_tmp_bka_table( |
666 | const key_range *start_key, |
667 | spider_string *str, |
668 | char *tmp_table_name, |
669 | int tmp_table_name_length, |
670 | int *db_name_pos |
671 | ); |
672 | int append_union_table_and_sql_for_bka( |
673 | const key_range *start_key |
674 | ); |
675 | int reuse_union_table_and_sql_for_bka(); |
676 | int append_insert_for_recovery( |
677 | ulong sql_type, |
678 | int link_idx |
679 | ); |
680 | int append_update( |
681 | const TABLE *table, |
682 | my_ptrdiff_t ptr_diff |
683 | ); |
684 | int append_update( |
685 | const TABLE *table, |
686 | my_ptrdiff_t ptr_diff, |
687 | int link_idx |
688 | ); |
689 | int append_delete( |
690 | const TABLE *table, |
691 | my_ptrdiff_t ptr_diff |
692 | ); |
693 | int append_delete( |
694 | const TABLE *table, |
695 | my_ptrdiff_t ptr_diff, |
696 | int link_idx |
697 | ); |
698 | int append_insert_part(); |
699 | int append_insert( |
700 | spider_string *str, |
701 | int link_idx |
702 | ); |
703 | int append_update_part(); |
704 | int append_update( |
705 | spider_string *str, |
706 | int link_idx |
707 | ); |
708 | int append_delete_part(); |
709 | int append_delete( |
710 | spider_string *str |
711 | ); |
712 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
713 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
714 | int append_increment_update_set_part(); |
715 | int append_increment_update_set( |
716 | spider_string *str |
717 | ); |
718 | #endif |
719 | #endif |
720 | int append_update_set_part(); |
721 | int append_update_set( |
722 | spider_string *str |
723 | ); |
724 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
725 | int append_direct_update_set_part(); |
726 | int append_direct_update_set( |
727 | spider_string *str |
728 | ); |
729 | int append_dup_update_pushdown_part( |
730 | const char *alias, |
731 | uint alias_length |
732 | ); |
733 | int append_update_columns_part( |
734 | const char *alias, |
735 | uint alias_length |
736 | ); |
737 | int check_update_columns_part(); |
738 | int append_update_columns( |
739 | spider_string *str, |
740 | const char *alias, |
741 | uint alias_length |
742 | ); |
743 | #endif |
744 | int append_select_part( |
745 | ulong sql_type |
746 | ); |
747 | int append_select( |
748 | spider_string *str, |
749 | ulong sql_type |
750 | ); |
751 | int append_table_select_part( |
752 | ulong sql_type |
753 | ); |
754 | int append_table_select( |
755 | spider_string *str |
756 | ); |
757 | int append_key_select_part( |
758 | ulong sql_type, |
759 | uint idx |
760 | ); |
761 | int append_key_select( |
762 | spider_string *str, |
763 | uint idx |
764 | ); |
765 | int append_minimum_select_part( |
766 | ulong sql_type |
767 | ); |
768 | int append_minimum_select( |
769 | spider_string *str, |
770 | ulong sql_type |
771 | ); |
772 | int append_table_select_with_alias( |
773 | spider_string *str, |
774 | const char *alias, |
775 | uint alias_length |
776 | ); |
777 | int append_key_select_with_alias( |
778 | spider_string *str, |
779 | const KEY *key_info, |
780 | const char *alias, |
781 | uint alias_length |
782 | ); |
783 | int append_minimum_select_with_alias( |
784 | spider_string *str, |
785 | const char *alias, |
786 | uint alias_length |
787 | ); |
788 | int append_select_columns_with_alias( |
789 | spider_string *str, |
790 | const char *alias, |
791 | uint alias_length |
792 | ); |
793 | int append_hint_after_table_part( |
794 | ulong sql_type |
795 | ); |
796 | int append_hint_after_table( |
797 | spider_string *str |
798 | ); |
799 | void set_where_pos( |
800 | ulong sql_type |
801 | ); |
802 | void set_where_to_pos( |
803 | ulong sql_type |
804 | ); |
805 | int check_item_type( |
806 | Item *item |
807 | ); |
808 | int append_values_connector_part( |
809 | ulong sql_type |
810 | ); |
811 | int append_values_connector( |
812 | spider_string *str |
813 | ); |
814 | int append_values_terminator_part( |
815 | ulong sql_type |
816 | ); |
817 | int append_values_terminator( |
818 | spider_string *str |
819 | ); |
820 | int append_union_table_connector_part( |
821 | ulong sql_type |
822 | ); |
823 | int append_union_table_connector( |
824 | spider_string *str |
825 | ); |
826 | int append_union_table_terminator_part( |
827 | ulong sql_type |
828 | ); |
829 | int append_union_table_terminator( |
830 | spider_string *str |
831 | ); |
832 | int append_key_column_values_part( |
833 | const key_range *start_key, |
834 | ulong sql_type |
835 | ); |
836 | int append_key_column_values( |
837 | spider_string *str, |
838 | const key_range *start_key |
839 | ); |
840 | int append_key_column_values_with_name_part( |
841 | const key_range *start_key, |
842 | ulong sql_type |
843 | ); |
844 | int append_key_column_values_with_name( |
845 | spider_string *str, |
846 | const key_range *start_key |
847 | ); |
848 | int append_key_where_part( |
849 | const key_range *start_key, |
850 | const key_range *end_key, |
851 | ulong sql_type |
852 | ); |
853 | int append_key_where( |
854 | spider_string *str, |
855 | spider_string *str_part, |
856 | spider_string *str_part2, |
857 | const key_range *start_key, |
858 | const key_range *end_key, |
859 | ulong sql_type, |
860 | bool set_order |
861 | ); |
862 | int append_is_null_part( |
863 | ulong sql_type, |
864 | KEY_PART_INFO *key_part, |
865 | const key_range *key, |
866 | const uchar **ptr, |
867 | bool key_eq, |
868 | bool tgt_final |
869 | ); |
870 | int append_is_null( |
871 | ulong sql_type, |
872 | spider_string *str, |
873 | spider_string *str_part, |
874 | spider_string *str_part2, |
875 | KEY_PART_INFO *key_part, |
876 | const key_range *key, |
877 | const uchar **ptr, |
878 | bool key_eq, |
879 | bool tgt_final |
880 | ); |
881 | int append_where_terminator_part( |
882 | ulong sql_type, |
883 | bool set_order, |
884 | int key_count |
885 | ); |
886 | int append_where_terminator( |
887 | ulong sql_type, |
888 | spider_string *str, |
889 | spider_string *str_part, |
890 | spider_string *str_part2, |
891 | bool set_order, |
892 | int key_count |
893 | ); |
894 | int append_match_where_part( |
895 | ulong sql_type |
896 | ); |
897 | int append_match_where( |
898 | spider_string *str |
899 | ); |
900 | int append_update_where( |
901 | spider_string *str, |
902 | const TABLE *table, |
903 | my_ptrdiff_t ptr_diff |
904 | ); |
905 | int append_condition_part( |
906 | const char *alias, |
907 | uint alias_length, |
908 | ulong sql_type, |
909 | bool test_flg |
910 | ); |
911 | int append_condition( |
912 | spider_string *str, |
913 | const char *alias, |
914 | uint alias_length, |
915 | bool start_where, |
916 | ulong sql_type |
917 | ); |
918 | int append_match_against_part( |
919 | ulong sql_type, |
920 | st_spider_ft_info *ft_info, |
921 | const char *alias, |
922 | uint alias_length |
923 | ); |
924 | int append_match_against( |
925 | spider_string *str, |
926 | st_spider_ft_info *ft_info, |
927 | const char *alias, |
928 | uint alias_length |
929 | ); |
930 | int append_match_select_part( |
931 | ulong sql_type, |
932 | const char *alias, |
933 | uint alias_length |
934 | ); |
935 | int append_match_select( |
936 | spider_string *str, |
937 | const char *alias, |
938 | uint alias_length |
939 | ); |
940 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
941 | int append_sum_select_part( |
942 | ulong sql_type, |
943 | const char *alias, |
944 | uint alias_length |
945 | ); |
946 | int append_sum_select( |
947 | spider_string *str, |
948 | const char *alias, |
949 | uint alias_length |
950 | ); |
951 | #endif |
952 | void set_order_pos( |
953 | ulong sql_type |
954 | ); |
955 | void set_order_to_pos( |
956 | ulong sql_type |
957 | ); |
958 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
959 | int append_group_by_part( |
960 | const char *alias, |
961 | uint alias_length, |
962 | ulong sql_type |
963 | ); |
964 | int append_group_by( |
965 | spider_string *str, |
966 | const char *alias, |
967 | uint alias_length |
968 | ); |
969 | #endif |
970 | int append_key_order_for_merge_with_alias_part( |
971 | const char *alias, |
972 | uint alias_length, |
973 | ulong sql_type |
974 | ); |
975 | int append_key_order_for_merge_with_alias( |
976 | spider_string *str, |
977 | const char *alias, |
978 | uint alias_length |
979 | ); |
980 | int append_key_order_for_direct_order_limit_with_alias_part( |
981 | const char *alias, |
982 | uint alias_length, |
983 | ulong sql_type |
984 | ); |
985 | int append_key_order_for_direct_order_limit_with_alias( |
986 | spider_string *str, |
987 | const char *alias, |
988 | uint alias_length |
989 | ); |
990 | int append_key_order_with_alias_part( |
991 | const char *alias, |
992 | uint alias_length, |
993 | ulong sql_type |
994 | ); |
995 | int append_key_order_for_handler( |
996 | spider_string *str, |
997 | const char *alias, |
998 | uint alias_length |
999 | ); |
1000 | int append_key_order_with_alias( |
1001 | spider_string *str, |
1002 | const char *alias, |
1003 | uint alias_length |
1004 | ); |
1005 | int append_limit_part( |
1006 | longlong offset, |
1007 | longlong limit, |
1008 | ulong sql_type |
1009 | ); |
1010 | int reappend_limit_part( |
1011 | longlong offset, |
1012 | longlong limit, |
1013 | ulong sql_type |
1014 | ); |
1015 | int append_limit( |
1016 | spider_string *str, |
1017 | longlong offset, |
1018 | longlong limit |
1019 | ); |
1020 | int append_select_lock_part( |
1021 | ulong sql_type |
1022 | ); |
1023 | int append_select_lock( |
1024 | spider_string *str |
1025 | ); |
1026 | int append_union_all_start_part( |
1027 | ulong sql_type |
1028 | ); |
1029 | int append_union_all_start( |
1030 | spider_string *str |
1031 | ); |
1032 | int append_union_all_part( |
1033 | ulong sql_type |
1034 | ); |
1035 | int append_union_all( |
1036 | spider_string *str |
1037 | ); |
1038 | int append_union_all_end_part( |
1039 | ulong sql_type |
1040 | ); |
1041 | int append_union_all_end( |
1042 | spider_string *str |
1043 | ); |
1044 | int append_multi_range_cnt_part( |
1045 | ulong sql_type, |
1046 | uint multi_range_cnt, |
1047 | bool with_comma |
1048 | ); |
1049 | int append_multi_range_cnt( |
1050 | spider_string *str, |
1051 | uint multi_range_cnt, |
1052 | bool with_comma |
1053 | ); |
1054 | int append_multi_range_cnt_with_name_part( |
1055 | ulong sql_type, |
1056 | uint multi_range_cnt |
1057 | ); |
1058 | int append_multi_range_cnt_with_name( |
1059 | spider_string *str, |
1060 | uint multi_range_cnt |
1061 | ); |
1062 | int append_open_handler_part( |
1063 | ulong sql_type, |
1064 | uint handler_id, |
1065 | SPIDER_CONN *conn, |
1066 | int link_idx |
1067 | ); |
1068 | int append_open_handler( |
1069 | spider_string *str, |
1070 | uint handler_id, |
1071 | SPIDER_CONN *conn, |
1072 | int link_idx |
1073 | ); |
1074 | int append_close_handler_part( |
1075 | ulong sql_type, |
1076 | int link_idx |
1077 | ); |
1078 | int append_close_handler( |
1079 | spider_string *str, |
1080 | int link_idx |
1081 | ); |
1082 | int append_insert_terminator_part( |
1083 | ulong sql_type |
1084 | ); |
1085 | int append_insert_terminator( |
1086 | spider_string *str |
1087 | ); |
1088 | int append_insert_values_part( |
1089 | ulong sql_type |
1090 | ); |
1091 | int append_insert_values( |
1092 | spider_string *str |
1093 | ); |
1094 | int append_into_part( |
1095 | ulong sql_type |
1096 | ); |
1097 | int append_into( |
1098 | spider_string *str |
1099 | ); |
1100 | void set_insert_to_pos( |
1101 | ulong sql_type |
1102 | ); |
1103 | int append_from_part( |
1104 | ulong sql_type, |
1105 | int link_idx |
1106 | ); |
1107 | int append_from( |
1108 | spider_string *str, |
1109 | ulong sql_type, |
1110 | int link_idx |
1111 | ); |
1112 | int append_flush_tables_part( |
1113 | ulong sql_type, |
1114 | int link_idx, |
1115 | bool lock |
1116 | ); |
1117 | int append_flush_tables( |
1118 | spider_string *str, |
1119 | int link_idx, |
1120 | bool lock |
1121 | ); |
1122 | int append_optimize_table_part( |
1123 | ulong sql_type, |
1124 | int link_idx |
1125 | ); |
1126 | int append_optimize_table( |
1127 | spider_string *str, |
1128 | int link_idx |
1129 | ); |
1130 | int append_analyze_table_part( |
1131 | ulong sql_type, |
1132 | int link_idx |
1133 | ); |
1134 | int append_analyze_table( |
1135 | spider_string *str, |
1136 | int link_idx |
1137 | ); |
1138 | int append_repair_table_part( |
1139 | ulong sql_type, |
1140 | int link_idx, |
1141 | HA_CHECK_OPT* check_opt |
1142 | ); |
1143 | int append_repair_table( |
1144 | spider_string *str, |
1145 | int link_idx, |
1146 | HA_CHECK_OPT* check_opt |
1147 | ); |
1148 | int append_check_table_part( |
1149 | ulong sql_type, |
1150 | int link_idx, |
1151 | HA_CHECK_OPT* check_opt |
1152 | ); |
1153 | int append_check_table( |
1154 | spider_string *str, |
1155 | int link_idx, |
1156 | HA_CHECK_OPT* check_opt |
1157 | ); |
1158 | int append_enable_keys_part( |
1159 | ulong sql_type, |
1160 | int link_idx |
1161 | ); |
1162 | int append_enable_keys( |
1163 | spider_string *str, |
1164 | int link_idx |
1165 | ); |
1166 | int append_disable_keys_part( |
1167 | ulong sql_type, |
1168 | int link_idx |
1169 | ); |
1170 | int append_disable_keys( |
1171 | spider_string *str, |
1172 | int link_idx |
1173 | ); |
1174 | int append_delete_all_rows_part( |
1175 | ulong sql_type |
1176 | ); |
1177 | int append_delete_all_rows( |
1178 | spider_string *str, |
1179 | ulong sql_type |
1180 | ); |
1181 | int append_truncate( |
1182 | spider_string *str, |
1183 | ulong sql_type, |
1184 | int link_idx |
1185 | ); |
1186 | int append_explain_select_part( |
1187 | key_range *start_key, |
1188 | key_range *end_key, |
1189 | ulong sql_type, |
1190 | int link_idx |
1191 | ); |
1192 | int append_explain_select( |
1193 | spider_string *str, |
1194 | key_range *start_key, |
1195 | key_range *end_key, |
1196 | ulong sql_type, |
1197 | int link_idx |
1198 | ); |
1199 | bool is_sole_projection_field( |
1200 | uint16 field_index |
1201 | ); |
1202 | bool is_bulk_insert_exec_period( |
1203 | bool bulk_end |
1204 | ); |
1205 | bool sql_is_filled_up( |
1206 | ulong sql_type |
1207 | ); |
1208 | bool sql_is_empty( |
1209 | ulong sql_type |
1210 | ); |
1211 | bool support_multi_split_read(); |
1212 | bool support_bulk_update(); |
1213 | int bulk_tmp_table_insert(); |
1214 | int bulk_tmp_table_insert( |
1215 | int link_idx |
1216 | ); |
1217 | int bulk_tmp_table_end_bulk_insert(); |
1218 | int bulk_tmp_table_rnd_init(); |
1219 | int bulk_tmp_table_rnd_next(); |
1220 | int bulk_tmp_table_rnd_end(); |
1221 | bool need_copy_for_update( |
1222 | int link_idx |
1223 | ); |
1224 | bool bulk_tmp_table_created(); |
1225 | int mk_bulk_tmp_table_and_bulk_start(); |
1226 | void rm_bulk_tmp_table(); |
1227 | int store_sql_to_bulk_tmp_table( |
1228 | spider_string *str, |
1229 | TABLE *tmp_table |
1230 | ); |
1231 | int restore_sql_from_bulk_tmp_table( |
1232 | spider_string *str, |
1233 | TABLE *tmp_table |
1234 | ); |
1235 | int insert_lock_tables_list( |
1236 | SPIDER_CONN *conn, |
1237 | int link_idx |
1238 | ); |
1239 | int append_lock_tables_list( |
1240 | SPIDER_CONN *conn, |
1241 | int link_idx, |
1242 | int *appended |
1243 | ); |
1244 | int realloc_sql( |
1245 | ulong *realloced |
1246 | ); |
1247 | int reset_sql( |
1248 | ulong sql_type |
1249 | ); |
1250 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
1251 | int reset_keys( |
1252 | ulong sql_type |
1253 | ); |
1254 | int reset_upds( |
1255 | ulong sql_type |
1256 | ); |
1257 | int reset_strs( |
1258 | ulong sql_type |
1259 | ); |
1260 | int reset_strs_pos( |
1261 | ulong sql_type |
1262 | ); |
1263 | int push_back_upds( |
1264 | SPIDER_HS_STRING_REF &info |
1265 | ); |
1266 | #endif |
1267 | bool need_lock_before_set_sql_for_exec( |
1268 | ulong sql_type |
1269 | ); |
1270 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
1271 | int set_sql_for_exec( |
1272 | ulong sql_type, |
1273 | int link_idx, |
1274 | SPIDER_LINK_IDX_CHAIN *link_idx_chain |
1275 | ); |
1276 | #endif |
1277 | int set_sql_for_exec( |
1278 | ulong sql_type, |
1279 | int link_idx |
1280 | ); |
1281 | int set_sql_for_exec( |
1282 | spider_db_copy_table *tgt_ct, |
1283 | ulong sql_type |
1284 | ); |
1285 | int execute_sql( |
1286 | ulong sql_type, |
1287 | SPIDER_CONN *conn, |
1288 | int quick_mode, |
1289 | int *need_mon |
1290 | ); |
1291 | int reset(); |
1292 | int sts_mode_exchange( |
1293 | int sts_mode |
1294 | ); |
1295 | int show_table_status( |
1296 | int link_idx, |
1297 | int sts_mode, |
1298 | uint flag |
1299 | ); |
1300 | int crd_mode_exchange( |
1301 | int crd_mode |
1302 | ); |
1303 | int show_index( |
1304 | int link_idx, |
1305 | int crd_mode |
1306 | ); |
1307 | int show_records( |
1308 | int link_idx |
1309 | ); |
1310 | int show_last_insert_id( |
1311 | int link_idx, |
1312 | ulonglong &last_insert_id |
1313 | ); |
1314 | ha_rows explain_select( |
1315 | key_range *start_key, |
1316 | key_range *end_key, |
1317 | int link_idx |
1318 | ); |
1319 | int lock_tables( |
1320 | int link_idx |
1321 | ); |
1322 | int unlock_tables( |
1323 | int link_idx |
1324 | ); |
1325 | int disable_keys( |
1326 | SPIDER_CONN *conn, |
1327 | int link_idx |
1328 | ); |
1329 | int enable_keys( |
1330 | SPIDER_CONN *conn, |
1331 | int link_idx |
1332 | ); |
1333 | int check_table( |
1334 | SPIDER_CONN *conn, |
1335 | int link_idx, |
1336 | HA_CHECK_OPT* check_opt |
1337 | ); |
1338 | int repair_table( |
1339 | SPIDER_CONN *conn, |
1340 | int link_idx, |
1341 | HA_CHECK_OPT* check_opt |
1342 | ); |
1343 | int analyze_table( |
1344 | SPIDER_CONN *conn, |
1345 | int link_idx |
1346 | ); |
1347 | int optimize_table( |
1348 | SPIDER_CONN *conn, |
1349 | int link_idx |
1350 | ); |
1351 | int flush_tables( |
1352 | SPIDER_CONN *conn, |
1353 | int link_idx, |
1354 | bool lock |
1355 | ); |
1356 | int flush_logs( |
1357 | SPIDER_CONN *conn, |
1358 | int link_idx |
1359 | ); |
1360 | int insert_opened_handler( |
1361 | SPIDER_CONN *conn, |
1362 | int link_idx |
1363 | ); |
1364 | int delete_opened_handler( |
1365 | SPIDER_CONN *conn, |
1366 | int link_idx |
1367 | ); |
1368 | int sync_from_clone_source( |
1369 | spider_db_handler *dbton_hdl |
1370 | ); |
1371 | bool support_use_handler( |
1372 | int use_handler |
1373 | ); |
1374 | void minimum_select_bitmap_create(); |
1375 | bool minimum_select_bit_is_set( |
1376 | uint field_index |
1377 | ); |
1378 | void copy_minimum_select_bitmap( |
1379 | uchar *bitmap |
1380 | ); |
1381 | int init_union_table_name_pos(); |
1382 | int set_union_table_name_pos(); |
1383 | int reset_union_table_name( |
1384 | spider_string *str, |
1385 | int link_idx, |
1386 | ulong sql_type |
1387 | ); |
1388 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
1389 | int append_from_and_tables_part( |
1390 | spider_fields *fields, |
1391 | ulong sql_type |
1392 | ); |
1393 | int reappend_tables_part( |
1394 | spider_fields *fields, |
1395 | ulong sql_type |
1396 | ); |
1397 | int append_where_part( |
1398 | ulong sql_type |
1399 | ); |
1400 | int append_having_part( |
1401 | ulong sql_type |
1402 | ); |
1403 | int append_item_type_part( |
1404 | Item *item, |
1405 | const char *alias, |
1406 | uint alias_length, |
1407 | bool use_fields, |
1408 | spider_fields *fields, |
1409 | ulong sql_type |
1410 | ); |
1411 | int append_list_item_select_part( |
1412 | List<Item> *select, |
1413 | const char *alias, |
1414 | uint alias_length, |
1415 | bool use_fields, |
1416 | spider_fields *fields, |
1417 | ulong sql_type |
1418 | ); |
1419 | int append_list_item_select( |
1420 | List<Item> *select, |
1421 | spider_string *str, |
1422 | const char *alias, |
1423 | uint alias_length, |
1424 | bool use_fields, |
1425 | spider_fields *fields |
1426 | ); |
1427 | int append_group_by_part( |
1428 | ORDER *order, |
1429 | const char *alias, |
1430 | uint alias_length, |
1431 | bool use_fields, |
1432 | spider_fields *fields, |
1433 | ulong sql_type |
1434 | ); |
1435 | int append_group_by( |
1436 | ORDER *order, |
1437 | spider_string *str, |
1438 | const char *alias, |
1439 | uint alias_length, |
1440 | bool use_fields, |
1441 | spider_fields *fields |
1442 | ); |
1443 | int append_order_by_part( |
1444 | ORDER *order, |
1445 | const char *alias, |
1446 | uint alias_length, |
1447 | bool use_fields, |
1448 | spider_fields *fields, |
1449 | ulong sql_type |
1450 | ); |
1451 | int append_order_by( |
1452 | ORDER *order, |
1453 | spider_string *str, |
1454 | const char *alias, |
1455 | uint alias_length, |
1456 | bool use_fields, |
1457 | spider_fields *fields |
1458 | ); |
1459 | #endif |
1460 | }; |
1461 | |
1462 | class spider_mysql_copy_table: public spider_db_copy_table |
1463 | { |
1464 | public: |
1465 | spider_mysql_share *mysql_share; |
1466 | spider_string sql; |
1467 | uint pos; |
1468 | spider_mysql_copy_table( |
1469 | spider_mysql_share *db_share |
1470 | ); |
1471 | ~spider_mysql_copy_table(); |
1472 | int init(); |
1473 | void set_sql_charset( |
1474 | CHARSET_INFO *cs |
1475 | ); |
1476 | int append_select_str(); |
1477 | int append_insert_str( |
1478 | int insert_flg |
1479 | ); |
1480 | int append_table_columns( |
1481 | TABLE_SHARE *table_share |
1482 | ); |
1483 | int append_from_str(); |
1484 | int append_table_name( |
1485 | int link_idx |
1486 | ); |
1487 | void set_sql_pos(); |
1488 | void set_sql_to_pos(); |
1489 | int append_copy_where( |
1490 | spider_db_copy_table *source_ct, |
1491 | KEY *key_info, |
1492 | ulong *last_row_pos, |
1493 | ulong *last_lengths |
1494 | ); |
1495 | int append_key_order_str( |
1496 | KEY *key_info, |
1497 | int start_pos, |
1498 | bool desc_flg |
1499 | ); |
1500 | int append_limit( |
1501 | longlong offset, |
1502 | longlong limit |
1503 | ); |
1504 | int append_into_str(); |
1505 | int append_open_paren_str(); |
1506 | int append_values_str(); |
1507 | int append_select_lock_str( |
1508 | int lock_mode |
1509 | ); |
1510 | int exec_query( |
1511 | SPIDER_CONN *conn, |
1512 | int quick_mode, |
1513 | int *need_mon |
1514 | ); |
1515 | int copy_key_row( |
1516 | spider_db_copy_table *source_ct, |
1517 | Field *field, |
1518 | ulong *row_pos, |
1519 | ulong *length, |
1520 | const char *joint_str, |
1521 | const int joint_length |
1522 | ); |
1523 | int copy_row( |
1524 | Field *field, |
1525 | SPIDER_DB_ROW *row |
1526 | ); |
1527 | int copy_rows( |
1528 | TABLE *table, |
1529 | SPIDER_DB_ROW *row, |
1530 | ulong **last_row_pos, |
1531 | ulong **last_lengths |
1532 | ); |
1533 | int copy_rows( |
1534 | TABLE *table, |
1535 | SPIDER_DB_ROW *row |
1536 | ); |
1537 | int append_insert_terminator(); |
1538 | int copy_insert_values( |
1539 | spider_db_copy_table *source_ct |
1540 | ); |
1541 | }; |
1542 | |