summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2009-10-16 19:58:26 +0400
committerKonstantin Osipov <kostja@sun.com>2009-10-16 19:58:26 +0400
commitf0ccd917cc2643f1f3b4ede4f742f735dfa50552 (patch)
tree4338d119cdec937cf4940fa680f04b7a3107d4da
parentabb5e74df6c9198e403cebf4418d17ab71e23352 (diff)
downloadmariadb-git-f0ccd917cc2643f1f3b4ede4f742f735dfa50552.tar.gz
Backport of:
---------------------------------------------------------- revno: 2630.22.11 committer: Konstantin Osipov <konstantin@mysql.com> branch nick: mysql-6.0-records timestamp: Mon 2008-08-11 16:40:09 +0400 message: Move read_record related functions to a new header - records.h sql/Makefile.am: Introduce records.h sql/handler.h: Forward-declare class handler (an unnecessary forward declaration was removed from mysql_priv.h). sql/item_subselect.cc: Make read_record function naming more consistent. Assign read_record function at once, no need to defer till read_first_record invocation. sql/mysql_priv.h: Include records.h, previously part of structs.h sql/records.cc: Use records.h sql/sql_select.h: Update to use new declarations. sql/structs.h: Move declarations of READ_RECORD and related functions to records.h
-rw-r--r--sql/Makefile.am2
-rw-r--r--sql/handler.h1
-rw-r--r--sql/item_subselect.cc6
-rw-r--r--sql/mysql_priv.h7
-rw-r--r--sql/records.cc5
-rw-r--r--sql/records.h75
-rw-r--r--sql/sql_select.cc4
-rw-r--r--sql/sql_select.h7
-rw-r--r--sql/structs.h25
9 files changed, 92 insertions, 40 deletions
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 600a6117ebf..d4c79851904 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -110,7 +110,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
sql_plugin.h authors.h event_parse_data.h \
event_data_objects.h event_scheduler.h \
sql_partition.h partition_info.h partition_element.h \
- contributors.h sql_servers.h sql_signal.h
+ contributors.h sql_servers.h sql_signal.h records.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
diff --git a/sql/handler.h b/sql/handler.h
index 41360998a37..f055af218b3 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -581,6 +581,7 @@ struct handler_iterator {
void *buffer;
};
+class handler;
/*
handlerton is a singleton structure - one instance per storage engine -
to provide access to storage engine functionality that works on the
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index da651cec70c..d16710f6660 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1863,7 +1863,8 @@ void subselect_uniquesubquery_engine::fix_length_and_dec(Item_cache **row)
DBUG_ASSERT(0);
}
-int init_read_record_seq(JOIN_TAB *tab);
+int read_first_record_seq(JOIN_TAB *tab);
+int rr_sequential(READ_RECORD *info);
int join_read_always_key_or_null(JOIN_TAB *tab);
int join_read_next_same_or_null(READ_RECORD *info);
@@ -1945,7 +1946,8 @@ int subselect_single_select_engine::exec()
/* Change the access method to full table scan */
tab->save_read_first_record= tab->read_first_record;
tab->save_read_record= tab->read_record.read_record;
- tab->read_first_record= init_read_record_seq;
+ tab->read_record.read_record= rr_sequential;
+ tab->read_first_record= read_first_record_seq;
tab->read_record.record= tab->table->record[0];
tab->read_record.thd= join->thd;
tab->read_record.ref_length= tab->table->file->ref_length;
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 3a7a0e3bdd7..cac647a0d03 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -878,6 +878,7 @@ bool general_log_write(THD *thd, enum enum_server_command command,
#include "tztime.h"
#ifdef MYSQL_SERVER
#include "sql_servers.h"
+#include "records.h"
#include "opt_range.h"
#ifdef HAVE_QUERY_CACHE
@@ -2235,12 +2236,6 @@ longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
int test_if_number(char *str,int *res,bool allow_wildcards);
void change_byte(uchar *,uint,char,char);
-void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
- SQL_SELECT *select, int use_record_cache,
- bool print_errors, bool disable_rr_cache);
-void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
- bool print_error, uint idx);
-void end_read_record(READ_RECORD *info);
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
uint s_length, SQL_SELECT *select,
ha_rows max_rows, bool sort_positions,
diff --git a/sql/records.cc b/sql/records.cc
index 9e040de3fda..9b5ea40478e 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -13,6 +13,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+#ifdef USE_PRAGMA_INTERFACE
+#pragma implementation /* gcc class implementation */
+#endif
/**
@file
@@ -21,8 +24,10 @@
Functions for easy reading of records, possible through a cache
*/
+#include "records.h"
#include "mysql_priv.h"
+
static int rr_quick(READ_RECORD *info);
int rr_sequential(READ_RECORD *info);
static int rr_from_tempfile(READ_RECORD *info);
diff --git a/sql/records.h b/sql/records.h
new file mode 100644
index 00000000000..9207a05f826
--- /dev/null
+++ b/sql/records.h
@@ -0,0 +1,75 @@
+#ifndef SQL_RECORDS_H
+#define SQL_RECORDS_H
+/* Copyright (C) 2008 Sun/MySQL
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface /* gcc class implementation */
+#endif
+#include <my_global.h> /* for uint typedefs */
+
+struct st_join_table;
+class handler;
+struct TABLE;
+class THD;
+class SQL_SELECT;
+
+/**
+ A context for reading through a single table using a chosen access method:
+ index read, scan, etc, use of cache, etc.
+
+ Use by:
+ READ_RECORD read_record;
+ init_read_record(&read_record, ...);
+ while (read_record.read_record())
+ {
+ ...
+ }
+ end_read_record();
+*/
+
+struct READ_RECORD
+{
+ typedef int (*Read_func)(READ_RECORD*);
+ typedef int (*Setup_func)(struct st_join_table*);
+
+ TABLE *table; /* Head-form */
+ handler *file;
+ TABLE **forms; /* head and ref forms */
+ Read_func read_record;
+ THD *thd;
+ SQL_SELECT *select;
+ uint cache_records;
+ uint ref_length,struct_length,reclength,rec_cache_size,error_offset;
+ uint index;
+ uchar *ref_pos; /* pointer to form->refpos */
+ uchar *record;
+ uchar *rec_buf; /* to read field values after filesort */
+ uchar *cache,*cache_pos,*cache_end,*read_positions;
+ struct st_io_cache *io_cache;
+ bool print_error, ignore_not_found_rows;
+
+public:
+ READ_RECORD() {}
+};
+
+void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
+ SQL_SELECT *select, int use_record_cache,
+ bool print_errors, bool disable_rr_cache);
+void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
+ bool print_error, uint idx);
+void end_read_record(READ_RECORD *info);
+
+#endif /* SQL_RECORDS_H */
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 488bd823b6a..9e94bd59bae 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -11881,10 +11881,8 @@ join_init_quick_read_record(JOIN_TAB *tab)
}
-int rr_sequential(READ_RECORD *info);
-int init_read_record_seq(JOIN_TAB *tab)
+int read_first_record_seq(JOIN_TAB *tab)
{
- tab->read_record.read_record= rr_sequential;
if (tab->read_record.file->ha_rnd_init(1))
return 1;
return (*tab->read_record.read_record)(&tab->read_record);
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 8311d7fdd2b..c725316f4dd 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -134,7 +134,6 @@ enum enum_nested_loop_state
typedef enum_nested_loop_state
(*Next_select_func)(JOIN *, struct st_join_table *, bool);
-typedef int (*Read_record_func)(struct st_join_table *tab);
Next_select_func setup_end_select_func(JOIN *join);
@@ -162,7 +161,7 @@ typedef struct st_join_table {
*/
uint packed_info;
- Read_record_func read_first_record;
+ READ_RECORD::Setup_func read_first_record;
Next_select_func next_select;
READ_RECORD read_record;
/*
@@ -170,8 +169,8 @@ typedef struct st_join_table {
if it is executed by an alternative full table scan when the left operand of
the subquery predicate is evaluated to NULL.
*/
- Read_record_func save_read_first_record;/* to save read_first_record */
- int (*save_read_record) (READ_RECORD *);/* to save read_record.read_record */
+ READ_RECORD::Setup_func save_read_first_record;/* to save read_first_record */
+ READ_RECORD::Read_func save_read_record;/* to save read_record.read_record */
double worst_seeks;
key_map const_keys; /**< Keys with constant part */
key_map checked_keys; /**< Keys checked in find_best */
diff --git a/sql/structs.h b/sql/structs.h
index c668b056a99..2c8e1121edc 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -18,6 +18,7 @@
struct TABLE;
class Field;
+class THD;
typedef struct st_date_time_format {
uchar positions[8];
@@ -115,30 +116,6 @@ typedef struct st_reginfo { /* Extra info about reg */
} REGINFO;
-struct st_read_record; /* For referense later */
-class SQL_SELECT;
-class THD;
-class handler;
-
-typedef struct st_read_record { /* Parameter to read_record */
- TABLE *table; /* Head-form */
- handler *file;
- TABLE **forms; /* head and ref forms */
- int (*read_record)(struct st_read_record *);
- THD *thd;
- SQL_SELECT *select;
- uint cache_records;
- uint ref_length,struct_length,reclength,rec_cache_size,error_offset;
- uint index;
- uchar *ref_pos; /* pointer to form->refpos */
- uchar *record;
- uchar *rec_buf; /* to read field values after filesort */
- uchar *cache,*cache_pos,*cache_end,*read_positions;
- IO_CACHE *io_cache;
- bool print_error, ignore_not_found_rows;
-} READ_RECORD;
-
-
/*
Originally MySQL used MYSQL_TIME structure inside server only, but since
4.1 it's exported to user in the new client API. Define aliases for