summaryrefslogtreecommitdiff
path: root/sql/sql_select.h
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2005-04-30 09:54:35 +0400
committerunknown <konstantin@mysql.com>2005-04-30 09:54:35 +0400
commit963e94ce4978f546ae5059631bf279eb0fc6e1ab (patch)
treef06357f2351844fc1200d435fac767983c3c39cf /sql/sql_select.h
parente9cc39c43f5e6bb38f11e0a50fb7f55acb85cc6b (diff)
downloadmariadb-git-963e94ce4978f546ae5059631bf279eb0fc6e1ab.tar.gz
A fix and a test case for Bug#9520 "SELECT DISTINCT crashes server
with cursor". The patch refactors do_select/sub_select functions, which implement the nested loop algorithm, and reuses them to fetch rows for cursors as well. Pushing with view.test failing (--ps-protocol). sql/sql_prepare.cc: Cursor::fetch() now returns void sql/sql_select.cc: A fix for Bug#9520 "SELECT DISTINCT crashes server with cursor": * rename sub_select returns codes to be able to track down what's going on in which case. * move record processing and outer join record processing to a separate function, out of sub_select read-record loop. * use generalized sub_select() nested loop function for cursors instead of own loop implementation used in Cursor::fetch() before sql/sql_select.h: Replace all return values of sub_select family with enum. Add JOIN::resume_nested_loop flag to indicate we are restarting the nested loop for execution of next chunk of cursor's rows. tests/mysql_client_test.c: A test case for Bug#9520 "SELECT DISTINCT crashes server with cursor"
Diffstat (limited to 'sql/sql_select.h')
-rw-r--r--sql/sql_select.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/sql/sql_select.h b/sql/sql_select.h
index c9a9b26d1b4..82efb62f7a3 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -91,7 +91,15 @@ enum join_type { JT_UNKNOWN,JT_SYSTEM,JT_CONST,JT_EQ_REF,JT_REF,JT_MAYBE_REF,
class JOIN;
-typedef int (*Next_select_func)(JOIN *,struct st_join_table *,bool);
+enum enum_nested_loop_state
+{
+ NESTED_LOOP_KILLED= -2, NESTED_LOOP_ERROR= -1,
+ NESTED_LOOP_OK= 0, NESTED_LOOP_NO_MORE_ROWS= 1,
+ NESTED_LOOP_QUERY_LIMIT= 3, NESTED_LOOP_CURSOR_LIMIT= 4
+};
+
+typedef enum_nested_loop_state
+(*Next_select_func)(JOIN *, struct st_join_table *, bool);
typedef int (*Read_record_func)(struct st_join_table *tab);
@@ -162,6 +170,11 @@ class JOIN :public Sql_alloc
uint send_group_parts;
bool sort_and_group,first_record,full_join,group, no_field_update;
bool do_send_rows;
+ /*
+ TRUE when we want to resume nested loop iterations when
+ fetching data from a cursor
+ */
+ bool resume_nested_loop;
table_map const_table_map,found_const_table_map,outer_join;
ha_rows send_records,found_records,examined_rows,row_limit, select_limit;
/*
@@ -263,6 +276,7 @@ class JOIN :public Sql_alloc
sort_and_group= 0;
first_record= 0;
do_send_rows= 1;
+ resume_nested_loop= FALSE;
send_records= 0;
found_records= 0;
fetch_limit= HA_POS_ERROR;
@@ -374,7 +388,7 @@ public:
void reset_thd(THD *thd);
int open(JOIN *join);
- int fetch(ulong num_rows);
+ void fetch(ulong num_rows);
void reset() { join= 0; }
bool is_open() const { return join != 0; }
void close();