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