~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1997, 2009, Innobase Oy. 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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
/******************************************************
20
Select
21
22
Created 12/19/1997 Heikki Tuuri
23
*******************************************************/
24
25
#include "que0que.h"
26
27
/*************************************************************************
28
Gets the plan node for the nth table in a join. */
29
UNIV_INLINE
30
plan_t*
31
sel_node_get_nth_plan(
32
/*==================*/
33
				/* out: plan node */
34
	sel_node_t*	node,	/* in: select node */
35
	ulint		i)	/* in: get ith plan node */
36
{
37
	ut_ad(i < node->n_tables);
38
39
	return(node->plans + i);
40
}
41
42
/*************************************************************************
43
Resets the cursor defined by sel_node to the SEL_NODE_OPEN state, which means
44
that it will start fetching from the start of the result set again, regardless
45
of where it was before, and it will set intention locks on the tables. */
46
UNIV_INLINE
47
void
48
sel_node_reset_cursor(
49
/*==================*/
50
	sel_node_t*	node)	/* in: select node */
51
{
52
	node->state = SEL_NODE_OPEN;
53
}
54
55
/**************************************************************************
56
Performs an execution step of an open or close cursor statement node. */
57
UNIV_INLINE
58
que_thr_t*
59
open_step(
60
/*======*/
61
				/* out: query thread to run next or NULL */
62
	que_thr_t*	thr)	/* in: query thread */
63
{
64
	sel_node_t*	sel_node;
65
	open_node_t*	node;
66
	ulint		err;
67
68
	ut_ad(thr);
69
70
	node = (open_node_t*) thr->run_node;
71
	ut_ad(que_node_get_type(node) == QUE_NODE_OPEN);
72
73
	sel_node = node->cursor_def;
74
75
	err = DB_SUCCESS;
76
77
	if (node->op_type == ROW_SEL_OPEN_CURSOR) {
78
79
		/*		if (sel_node->state == SEL_NODE_CLOSED) { */
80
81
		sel_node_reset_cursor(sel_node);
82
		/*		} else {
83
		err = DB_ERROR;
84
		} */
85
	} else {
86
		if (sel_node->state != SEL_NODE_CLOSED) {
87
88
			sel_node->state = SEL_NODE_CLOSED;
89
		} else {
90
			err = DB_ERROR;
91
		}
92
	}
93
94
	if (UNIV_EXPECT(err, DB_SUCCESS) != DB_SUCCESS) {
95
		/* SQL error detected */
96
		fprintf(stderr, "SQL error %lu\n", (ulong) err);
97
98
		ut_error;
99
	}
100
101
	thr->run_node = que_node_get_parent(node);
102
103
	return(thr);
104
}