summaryrefslogtreecommitdiff
path: root/storage/xtradb/include/row0sel.ic
blob: d83a344883283fb3d7c643edc9d68fa09e1ca017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*****************************************************************************

Copyright (c) 1997, 2009, Oracle and/or its affiliates. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA

*****************************************************************************/

/**************************************************//**
@file include/row0sel.ic
Select

Created 12/19/1997 Heikki Tuuri
*******************************************************/

#include "que0que.h"

/*********************************************************************//**
Gets the plan node for the nth table in a join.
@return	plan node */
UNIV_INLINE
plan_t*
sel_node_get_nth_plan(
/*==================*/
	sel_node_t*	node,	/*!< in: select node */
	ulint		i)	/*!< in: get ith plan node */
{
	ut_ad(i < node->n_tables);

	return(node->plans + i);
}

/*********************************************************************//**
Resets the cursor defined by sel_node to the SEL_NODE_OPEN state, which means
that it will start fetching from the start of the result set again, regardless
of where it was before, and it will set intention locks on the tables. */
UNIV_INLINE
void
sel_node_reset_cursor(
/*==================*/
	sel_node_t*	node)	/*!< in: select node */
{
	node->state = SEL_NODE_OPEN;
}

/**********************************************************************//**
Performs an execution step of an open or close cursor statement node.
@return	query thread to run next or NULL */
UNIV_INLINE
que_thr_t*
open_step(
/*======*/
	que_thr_t*	thr)	/*!< in: query thread */
{
	sel_node_t*	sel_node;
	open_node_t*	node;
	ulint		err;

	ut_ad(thr);

	node = (open_node_t*) thr->run_node;
	ut_ad(que_node_get_type(node) == QUE_NODE_OPEN);

	sel_node = node->cursor_def;

	err = DB_SUCCESS;

	if (node->op_type == ROW_SEL_OPEN_CURSOR) {

		/*		if (sel_node->state == SEL_NODE_CLOSED) { */

		sel_node_reset_cursor(sel_node);
		/*		} else {
		err = DB_ERROR;
		} */
	} else {
		if (sel_node->state != SEL_NODE_CLOSED) {

			sel_node->state = SEL_NODE_CLOSED;
		} else {
			err = DB_ERROR;
		}
	}

	if (err != DB_SUCCESS) {
		/* SQL error detected */
		fprintf(stderr, "SQL error %lu\n", (ulong) err);

		ut_error;
	}

	thr->run_node = que_node_get_parent(node);

	return(thr);
}