| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 1997, 2014, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify it under |
| 6 | the terms of the GNU General Public License as published by the Free Software |
| 7 | Foundation; version 2 of the License. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License along with |
| 14 | this program; if not, write to the Free Software Foundation, Inc., |
| 15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 16 | |
| 17 | *****************************************************************************/ |
| 18 | |
| 19 | /**************************************************//** |
| 20 | @file include/row0sel.ic |
| 21 | Select |
| 22 | |
| 23 | Created 12/19/1997 Heikki Tuuri |
| 24 | *******************************************************/ |
| 25 | |
| 26 | #include "que0que.h" |
| 27 | |
| 28 | /*********************************************************************//** |
| 29 | Gets the plan node for the nth table in a join. |
| 30 | @return plan node */ |
| 31 | UNIV_INLINE |
| 32 | plan_t* |
| 33 | sel_node_get_nth_plan( |
| 34 | /*==================*/ |
| 35 | sel_node_t* node, /*!< in: select node */ |
| 36 | ulint i) /*!< in: get ith plan node */ |
| 37 | { |
| 38 | ut_ad(i < node->n_tables); |
| 39 | |
| 40 | return(node->plans + i); |
| 41 | } |
| 42 | |
| 43 | /*********************************************************************//** |
| 44 | Resets the cursor defined by sel_node to the SEL_NODE_OPEN state, which means |
| 45 | that it will start fetching from the start of the result set again, regardless |
| 46 | of where it was before, and it will set intention locks on the tables. */ |
| 47 | UNIV_INLINE |
| 48 | void |
| 49 | sel_node_reset_cursor( |
| 50 | /*==================*/ |
| 51 | sel_node_t* node) /*!< in: select node */ |
| 52 | { |
| 53 | node->state = SEL_NODE_OPEN; |
| 54 | } |
| 55 | |
| 56 | /**********************************************************************//** |
| 57 | Performs an execution step of an open or close cursor statement node. |
| 58 | @return query thread to run next or NULL */ |
| 59 | UNIV_INLINE |
| 60 | que_thr_t* |
| 61 | open_step( |
| 62 | /*======*/ |
| 63 | que_thr_t* thr) /*!< in: query thread */ |
| 64 | { |
| 65 | sel_node_t* sel_node; |
| 66 | open_node_t* node; |
| 67 | ulint err; |
| 68 | |
| 69 | ut_ad(thr); |
| 70 | |
| 71 | node = (open_node_t*) thr->run_node; |
| 72 | ut_ad(que_node_get_type(node) == QUE_NODE_OPEN); |
| 73 | |
| 74 | sel_node = node->cursor_def; |
| 75 | |
| 76 | err = DB_SUCCESS; |
| 77 | |
| 78 | if (node->op_type == ROW_SEL_OPEN_CURSOR) { |
| 79 | |
| 80 | /* if (sel_node->state == SEL_NODE_CLOSED) { */ |
| 81 | |
| 82 | sel_node_reset_cursor(sel_node); |
| 83 | /* } else { |
| 84 | err = DB_ERROR; |
| 85 | } */ |
| 86 | } else { |
| 87 | if (sel_node->state != SEL_NODE_CLOSED) { |
| 88 | |
| 89 | sel_node->state = SEL_NODE_CLOSED; |
| 90 | } else { |
| 91 | err = DB_ERROR; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (err != DB_SUCCESS) { |
| 96 | /* SQL error detected */ |
| 97 | fprintf(stderr, "SQL error %lu\n" , (ulong) err); |
| 98 | |
| 99 | ut_error; |
| 100 | } |
| 101 | |
| 102 | thr->run_node = que_node_get_parent(node); |
| 103 | |
| 104 | return(thr); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /** Searches for rows in the database. This is used in the interface to |
| 109 | MySQL. This function opens a cursor, and also implements fetch next |
| 110 | and fetch prev. NOTE that if we do a search with a full key value |
| 111 | from a unique index (ROW_SEL_EXACT), then we will not store the cursor |
| 112 | position and fetch next or fetch prev must not be tried to the cursor! |
| 113 | |
| 114 | @param[out] buf buffer for the fetched row in MySQL format |
| 115 | @param[in] mode search mode PAGE_CUR_L |
| 116 | @param[in,out] prebuilt prebuilt struct for the table handler; |
| 117 | this contains the info to search_tuple, |
| 118 | index; if search tuple contains 0 field then |
| 119 | we position the cursor at start or the end of |
| 120 | index, depending on 'mode' |
| 121 | @param[in] match_mode 0 or ROW_SEL_EXACT or ROW_SEL_EXACT_PREFIX |
| 122 | @param[in] direction 0 or ROW_SEL_NEXT or ROW_SEL_PREV; |
| 123 | Note: if this is != 0, then prebuilt must has a |
| 124 | pcur with stored position! In opening of a |
| 125 | cursor 'direction' should be 0. |
| 126 | @return DB_SUCCESS, DB_RECORD_NOT_FOUND, DB_END_OF_INDEX, DB_DEADLOCK, |
| 127 | DB_LOCK_TABLE_FULL, DB_CORRUPTION, or DB_TOO_BIG_RECORD */ |
| 128 | UNIV_INLINE |
| 129 | dberr_t |
| 130 | row_search_for_mysql( |
| 131 | byte* buf, |
| 132 | page_cur_mode_t mode, |
| 133 | row_prebuilt_t* prebuilt, |
| 134 | ulint match_mode, |
| 135 | ulint direction) |
| 136 | { |
| 137 | return(row_search_mvcc(buf, mode, prebuilt, match_mode, direction)); |
| 138 | } |
| 139 | |