2002-10-28 14:44:19 +01:00
|
|
|
/* Copyright (C) 2000 MySQL AB
|
|
|
|
|
|
|
|
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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2002-10-28 14:44:19 +01:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
struct st_find_field
|
|
|
|
{
|
|
|
|
const char *table_name, *field_name;
|
|
|
|
Field *field;
|
|
|
|
};
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/* Used fields */
|
|
|
|
|
|
|
|
static struct st_find_field init_used_fields[]=
|
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
{ "help_topic", "help_topic_id", 0},
|
|
|
|
{ "help_topic", "name", 0},
|
|
|
|
{ "help_topic", "help_category_id", 0},
|
|
|
|
{ "help_topic", "description", 0},
|
|
|
|
{ "help_topic", "example", 0},
|
|
|
|
|
|
|
|
{ "help_category", "help_category_id", 0},
|
|
|
|
{ "help_category", "parent_category_id", 0},
|
|
|
|
{ "help_category", "name", 0},
|
|
|
|
|
|
|
|
{ "help_keyword", "help_keyword_id", 0},
|
|
|
|
{ "help_keyword", "name", 0},
|
|
|
|
|
|
|
|
{ "help_relation", "help_topic_id", 0},
|
|
|
|
{ "help_relation", "help_keyword_id", 0}
|
2003-02-12 20:55:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum enum_used_fields
|
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
help_topic_help_topic_id= 0,
|
2004-06-23 12:29:05 +02:00
|
|
|
help_topic_name,
|
2003-05-29 23:47:31 +02:00
|
|
|
help_topic_help_category_id,
|
2004-06-23 12:29:05 +02:00
|
|
|
help_topic_description,
|
2003-05-29 23:47:31 +02:00
|
|
|
help_topic_example,
|
|
|
|
|
|
|
|
help_category_help_category_id,
|
|
|
|
help_category_parent_category_id,
|
|
|
|
help_category_name,
|
|
|
|
|
|
|
|
help_keyword_help_keyword_id,
|
|
|
|
help_keyword_name,
|
|
|
|
|
2004-06-23 12:29:05 +02:00
|
|
|
help_relation_help_topic_id,
|
2003-05-29 23:47:31 +02:00
|
|
|
help_relation_help_keyword_id
|
2003-02-12 20:55:37 +01:00
|
|
|
};
|
2002-12-20 14:57:24 +01:00
|
|
|
|
2003-06-24 11:10:35 +02:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/*
|
2004-06-23 12:29:05 +02:00
|
|
|
Fill st_find_field structure with pointers to fields
|
2003-05-29 23:47:31 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
init_fields()
|
|
|
|
thd Thread handler
|
|
|
|
tables list of all tables for fields
|
|
|
|
find_fields array of structures
|
|
|
|
count size of previous array
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0 all ok
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
1 one of the fileds was not found
|
2003-05-29 23:47:31 +02:00
|
|
|
*/
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
static bool init_fields(THD *thd, TABLE_LIST *tables,
|
2003-05-29 23:47:31 +02:00
|
|
|
struct st_find_field *find_fields, uint count)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2005-07-01 06:05:42 +02:00
|
|
|
Name_resolution_context *context= &thd->lex->select_lex.context;
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_ENTER("init_fields");
|
2005-07-01 06:05:42 +02:00
|
|
|
context->resolve_in_table_list_only(tables);
|
2003-05-29 23:47:31 +02:00
|
|
|
for (; count-- ; find_fields++)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-02-12 20:55:37 +01:00
|
|
|
/* We have to use 'new' here as field will be re_linked on free */
|
2005-07-01 06:05:42 +02:00
|
|
|
Item_field *field= new Item_field(context,
|
|
|
|
"mysql", find_fields->table_name,
|
2003-05-29 23:47:31 +02:00
|
|
|
find_fields->field_name);
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
if (!(find_fields->field= find_field_in_tables(thd, field, tables, NULL,
|
2005-07-02 23:51:02 +02:00
|
|
|
0, REPORT_ALL_ERRORS, 1,
|
|
|
|
TRUE)))
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_RETURN(1);
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_RETURN(0);
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
|
2003-06-24 11:10:35 +02:00
|
|
|
/*
|
2003-05-29 23:47:31 +02:00
|
|
|
Returns variants of found topic for help (if it is just single topic,
|
|
|
|
returns description and example, or else returns only names..)
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
memorize_variant_topic()
|
|
|
|
|
|
|
|
thd Thread handler
|
|
|
|
topics Table of topics
|
|
|
|
count number of alredy found topics
|
|
|
|
find_fields Filled array of information for work with fields
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
names array of names of found topics (out)
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
name name of found topic (out)
|
|
|
|
description description of found topic (out)
|
|
|
|
example example for found topic (out)
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
Field 'names' is set only if more than one topic is found.
|
2004-06-23 12:29:05 +02:00
|
|
|
Fields 'name', 'description', 'example' are set only if
|
2003-05-29 23:47:31 +02:00
|
|
|
found exactly one topic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void memorize_variant_topic(THD *thd, TABLE *topics, int count,
|
2004-06-23 12:29:05 +02:00
|
|
|
struct st_find_field *find_fields,
|
2003-05-29 23:47:31 +02:00
|
|
|
List<String> *names,
|
|
|
|
String *name, String *description, String *example)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("memorize_variant_topic");
|
2004-11-08 00:13:54 +01:00
|
|
|
MEM_ROOT *mem_root= thd->mem_root;
|
2003-05-29 23:47:31 +02:00
|
|
|
if (count==0)
|
|
|
|
{
|
|
|
|
get_field(mem_root,find_fields[help_topic_name].field, name);
|
|
|
|
get_field(mem_root,find_fields[help_topic_description].field, description);
|
|
|
|
get_field(mem_root,find_fields[help_topic_example].field, example);
|
|
|
|
}
|
2004-06-23 12:29:05 +02:00
|
|
|
else
|
2003-05-29 23:47:31 +02:00
|
|
|
{
|
2003-06-24 11:10:35 +02:00
|
|
|
if (count == 1)
|
2003-05-29 23:47:31 +02:00
|
|
|
names->push_back(name);
|
2004-11-08 00:13:54 +01:00
|
|
|
String *new_name= new (thd->mem_root) String;
|
2003-05-29 23:47:31 +02:00
|
|
|
get_field(mem_root,find_fields[help_topic_name].field,new_name);
|
|
|
|
names->push_back(new_name);
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/*
|
|
|
|
Look for topics by mask
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
search_topics()
|
2003-05-29 23:47:31 +02:00
|
|
|
thd Thread handler
|
|
|
|
topics Table of topics
|
|
|
|
find_fields Filled array of info for fields
|
|
|
|
select Function to test for matching help topic.
|
|
|
|
Normally 'help_topic.name like 'bit%'
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
RETURN VALUES
|
2003-05-29 23:47:31 +02:00
|
|
|
# number of topics found
|
|
|
|
|
|
|
|
names array of names of found topics (out)
|
|
|
|
name name of found topic (out)
|
|
|
|
description description of found topic (out)
|
|
|
|
example example for found topic (out)
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
Field 'names' is set only if more than one topic was found.
|
2004-06-23 12:29:05 +02:00
|
|
|
Fields 'name', 'description', 'example' are set only if
|
2003-05-29 23:47:31 +02:00
|
|
|
exactly one topic was found.
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
*/
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
int search_topics(THD *thd, TABLE *topics, struct st_find_field *find_fields,
|
|
|
|
SQL_SELECT *select, List<String> *names,
|
|
|
|
String *name, String *description, String *example)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_ENTER("search_topics");
|
2002-10-28 14:44:19 +01:00
|
|
|
int count= 0;
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
READ_RECORD read_record_info;
|
|
|
|
init_read_record(&read_record_info, thd, topics, select,1,0);
|
|
|
|
while (!read_record_info.read_record(&read_record_info))
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2004-06-23 12:29:05 +02:00
|
|
|
if (!select->cond->val_int()) // Doesn't match like
|
2002-10-28 14:44:19 +01:00
|
|
|
continue;
|
2003-05-29 23:47:31 +02:00
|
|
|
memorize_variant_topic(thd,topics,count,find_fields,
|
|
|
|
names,name,description,example);
|
2003-02-12 20:55:37 +01:00
|
|
|
count++;
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2003-02-12 20:55:37 +01:00
|
|
|
end_read_record(&read_record_info);
|
2003-05-29 23:47:31 +02:00
|
|
|
|
2002-10-28 14:44:19 +01:00
|
|
|
DBUG_RETURN(count);
|
|
|
|
}
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/*
|
2003-05-29 23:47:31 +02:00
|
|
|
Look for keyword by mask
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2003-05-29 23:47:31 +02:00
|
|
|
search_keyword()
|
|
|
|
thd Thread handler
|
|
|
|
keywords Table of keywords
|
|
|
|
find_fields Filled array of info for fields
|
|
|
|
select Function to test for matching keyword.
|
|
|
|
Normally 'help_keyword.name like 'bit%'
|
|
|
|
|
|
|
|
key_id help_keyword_if of found topics (out)
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
RETURN VALUES
|
2003-05-29 23:47:31 +02:00
|
|
|
0 didn't find any topics matching the mask
|
|
|
|
1 found exactly one topic matching the mask
|
|
|
|
2 found more then one topic matching the mask
|
2003-02-12 20:55:37 +01:00
|
|
|
*/
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
int search_keyword(THD *thd, TABLE *keywords, struct st_find_field *find_fields,
|
|
|
|
SQL_SELECT *select, int *key_id)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_ENTER("search_keyword");
|
2002-10-28 14:44:19 +01:00
|
|
|
int count= 0;
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
READ_RECORD read_record_info;
|
|
|
|
init_read_record(&read_record_info, thd, keywords, select,1,0);
|
|
|
|
while (!read_record_info.read_record(&read_record_info) && count<2)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
if (!select->cond->val_int()) // Dosn't match like
|
2003-02-12 20:55:37 +01:00
|
|
|
continue;
|
2003-05-29 23:47:31 +02:00
|
|
|
|
2003-06-04 05:59:32 +02:00
|
|
|
*key_id= (int)find_fields[help_keyword_help_keyword_id].field->val_int();
|
2003-05-29 23:47:31 +02:00
|
|
|
|
|
|
|
count++;
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2003-02-12 20:55:37 +01:00
|
|
|
end_read_record(&read_record_info);
|
2003-05-29 23:47:31 +02:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
DBUG_RETURN(count);
|
|
|
|
}
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/*
|
2003-05-29 23:47:31 +02:00
|
|
|
Look for all topics with keyword
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
SYNOPSIS
|
2003-05-29 23:47:31 +02:00
|
|
|
get_topics_for_keyword()
|
|
|
|
thd Thread handler
|
|
|
|
topics Table of topics
|
|
|
|
relations Table of m:m relation "topic/keyword"
|
|
|
|
find_fields Filled array of info for fields
|
|
|
|
key_id Primary index to use to find for keyword
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
RETURN VALUES
|
2003-05-29 23:47:31 +02:00
|
|
|
# number of topics found
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
names array of name of found topics (out)
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
name name of found topic (out)
|
|
|
|
description description of found topic (out)
|
|
|
|
example example for found topic (out)
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2004-06-23 12:29:05 +02:00
|
|
|
NOTE
|
2003-05-29 23:47:31 +02:00
|
|
|
Field 'names' is set only if more than one topic was found.
|
2004-06-23 12:29:05 +02:00
|
|
|
Fields 'name', 'description', 'example' are set only if
|
2003-05-29 23:47:31 +02:00
|
|
|
exactly one topic was found.
|
2003-02-12 20:55:37 +01:00
|
|
|
*/
|
2002-10-28 14:44:19 +01:00
|
|
|
|
2004-06-23 12:29:05 +02:00
|
|
|
int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations,
|
2003-05-29 23:47:31 +02:00
|
|
|
struct st_find_field *find_fields, int16 key_id,
|
|
|
|
List<String> *names,
|
|
|
|
String *name, String *description, String *example)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
char buff[8]; // Max int length
|
|
|
|
int count= 0;
|
2003-02-12 20:55:37 +01:00
|
|
|
int iindex_topic, iindex_relations;
|
2003-05-29 23:47:31 +02:00
|
|
|
Field *rtopic_id, *rkey_id;
|
|
|
|
|
|
|
|
DBUG_ENTER("get_topics_for_keyword");
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2004-01-14 13:01:55 +01:00
|
|
|
if ((iindex_topic= find_type((char*) primary_key_name,
|
2005-01-06 12:00:13 +01:00
|
|
|
&topics->s->keynames, 1+2)-1)<0 ||
|
2004-01-14 13:01:55 +01:00
|
|
|
(iindex_relations= find_type((char*) primary_key_name,
|
2005-01-06 12:00:13 +01:00
|
|
|
&relations->s->keynames, 1+2)-1)<0)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0));
|
2003-02-12 20:55:37 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
rtopic_id= find_fields[help_relation_help_topic_id].field;
|
2003-05-29 23:47:31 +02:00
|
|
|
rkey_id= find_fields[help_relation_help_keyword_id].field;
|
2004-06-23 12:29:05 +02:00
|
|
|
|
|
|
|
topics->file->ha_index_init(iindex_topic);
|
|
|
|
relations->file->ha_index_init(iindex_relations);
|
|
|
|
|
Added option --valgrind-mysqltest to mysql-test-run
Added flag to Field::store(longlong) to specify if value is unsigned.
This fixes bug #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)
Fixed warning from valgrind in CREATE ... SELECT
Fixed double free of mysql.options if reconnect failed
mysql-test/mysql-test-run.sh:
Added option --valgrind-mysqltest to allow one to run mysqltest with valgrind
mysql-test/r/bigint.result:
Update results after fix for Field::store(longlong)
mysql-test/r/range.result:
Update results after fix for Field::store(longlong)
mysql-test/r/strict.result:
Update results after fix for Field::store(longlong)
(This fixes some wrong results when storing things into bigint columns)
mysql-test/r/type_ranges.result:
Update results after fix for Field::store(longlong)
mysql-test/t/bigint.test:
Added testing for #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)
mysql-test/t/innodb.test:
Removed comments affected by this bug fix
mysql-test/t/mysqldump.test:
Fixed result to not depend on existing config files
mysql-test/t/range.test:
0xff numbers are now unsigned
mysql-test/t/strict.test:
Added errors for things that previously (wrongly) succeeded
sql-common/client.c:
Fixed double free of mysql.options if reconnect failed
sql/field.cc:
Added flag to Field::store(longlong) to specify if value is unsigned
sql/field.h:
Added flag to Field::store(longlong) to specify if value is unsigned
sql/field_conv.cc:
Fixed calls to Field::store(longlong,flag)
sql/ha_ndbcluster.cc:
Fixed calls to Field::store(longlong,flag)
sql/handler.cc:
Fixed calls to Field::store(longlong,flag)
sql/item.cc:
Fixed calls to Field::store(longlong,flag)
sql/item_sum.cc:
Fixed calls to Field::store(longlong,flag)
sql/sp.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_acl.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_help.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_show.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_table.cc:
Fixed varning from valgrind
sql/sql_udf.cc:
Fixed calls to Field::store(longlong,flag)
sql/tztime.cc:
Fixed calls to Field::store(longlong,flag)
sql/unireg.cc:
Fixed calls to Field::store(longlong,flag)
2005-09-14 00:41:44 +02:00
|
|
|
rkey_id->store((longlong) key_id, TRUE);
|
2004-12-06 01:00:37 +01:00
|
|
|
rkey_id->get_key_image(buff, rkey_id->pack_length(), Field::itRAW);
|
2003-02-12 20:55:37 +01:00
|
|
|
int key_res= relations->file->index_read(relations->record[0],
|
2003-05-29 23:47:31 +02:00
|
|
|
(byte *)buff, rkey_id->pack_length(),
|
2003-02-12 20:55:37 +01:00
|
|
|
HA_READ_KEY_EXACT);
|
2004-06-23 12:29:05 +02:00
|
|
|
|
|
|
|
for ( ;
|
2003-05-29 23:47:31 +02:00
|
|
|
!key_res && key_id == (int16) rkey_id->val_int() ;
|
2003-02-12 20:55:37 +01:00
|
|
|
key_res= relations->file->index_next(relations->record[0]))
|
|
|
|
{
|
|
|
|
char topic_id_buff[8];
|
|
|
|
longlong topic_id= rtopic_id->val_int();
|
|
|
|
Field *field= find_fields[help_topic_help_topic_id].field;
|
Added option --valgrind-mysqltest to mysql-test-run
Added flag to Field::store(longlong) to specify if value is unsigned.
This fixes bug #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)
Fixed warning from valgrind in CREATE ... SELECT
Fixed double free of mysql.options if reconnect failed
mysql-test/mysql-test-run.sh:
Added option --valgrind-mysqltest to allow one to run mysqltest with valgrind
mysql-test/r/bigint.result:
Update results after fix for Field::store(longlong)
mysql-test/r/range.result:
Update results after fix for Field::store(longlong)
mysql-test/r/strict.result:
Update results after fix for Field::store(longlong)
(This fixes some wrong results when storing things into bigint columns)
mysql-test/r/type_ranges.result:
Update results after fix for Field::store(longlong)
mysql-test/t/bigint.test:
Added testing for #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)
mysql-test/t/innodb.test:
Removed comments affected by this bug fix
mysql-test/t/mysqldump.test:
Fixed result to not depend on existing config files
mysql-test/t/range.test:
0xff numbers are now unsigned
mysql-test/t/strict.test:
Added errors for things that previously (wrongly) succeeded
sql-common/client.c:
Fixed double free of mysql.options if reconnect failed
sql/field.cc:
Added flag to Field::store(longlong) to specify if value is unsigned
sql/field.h:
Added flag to Field::store(longlong) to specify if value is unsigned
sql/field_conv.cc:
Fixed calls to Field::store(longlong,flag)
sql/ha_ndbcluster.cc:
Fixed calls to Field::store(longlong,flag)
sql/handler.cc:
Fixed calls to Field::store(longlong,flag)
sql/item.cc:
Fixed calls to Field::store(longlong,flag)
sql/item_sum.cc:
Fixed calls to Field::store(longlong,flag)
sql/sp.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_acl.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_help.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_show.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_table.cc:
Fixed varning from valgrind
sql/sql_udf.cc:
Fixed calls to Field::store(longlong,flag)
sql/tztime.cc:
Fixed calls to Field::store(longlong,flag)
sql/unireg.cc:
Fixed calls to Field::store(longlong,flag)
2005-09-14 00:41:44 +02:00
|
|
|
field->store((longlong) topic_id, TRUE);
|
2004-12-06 01:00:37 +01:00
|
|
|
field->get_key_image(topic_id_buff, field->pack_length(), Field::itRAW);
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-02-20 23:14:37 +01:00
|
|
|
if (!topics->file->index_read(topics->record[0], (byte *)topic_id_buff,
|
2003-05-29 23:47:31 +02:00
|
|
|
field->pack_length(), HA_READ_KEY_EXACT))
|
|
|
|
{
|
|
|
|
memorize_variant_topic(thd,topics,count,find_fields,
|
|
|
|
names,name,description,example);
|
|
|
|
count++;
|
|
|
|
}
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2004-06-23 12:29:05 +02:00
|
|
|
topics->file->ha_index_end();
|
|
|
|
relations->file->ha_index_end();
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_RETURN(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Look for categories by mask
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
search_categories()
|
|
|
|
thd THD for init_read_record
|
|
|
|
categories Table of categories
|
|
|
|
find_fields Filled array of info for fields
|
|
|
|
select Function to test for if matching help topic.
|
|
|
|
Normally 'help_vategory.name like 'bit%'
|
|
|
|
names List of found categories names (out)
|
|
|
|
res_id Primary index of found category (only if
|
|
|
|
found exactly one category)
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
# Number of categories found
|
|
|
|
*/
|
|
|
|
|
|
|
|
int search_categories(THD *thd, TABLE *categories,
|
|
|
|
struct st_find_field *find_fields,
|
|
|
|
SQL_SELECT *select, List<String> *names, int16 *res_id)
|
|
|
|
{
|
|
|
|
Field *pfname= find_fields[help_category_name].field;
|
|
|
|
Field *pcat_id= find_fields[help_category_help_category_id].field;
|
|
|
|
int count= 0;
|
2004-06-23 12:29:05 +02:00
|
|
|
READ_RECORD read_record_info;
|
2003-05-29 23:47:31 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("search_categories");
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
init_read_record(&read_record_info, thd, categories, select,1,0);
|
|
|
|
while (!read_record_info.read_record(&read_record_info))
|
|
|
|
{
|
|
|
|
if (select && !select->cond->val_int())
|
|
|
|
continue;
|
2004-11-08 00:13:54 +01:00
|
|
|
String *lname= new (thd->mem_root) String;
|
|
|
|
get_field(thd->mem_root,pfname,lname);
|
2003-05-29 23:47:31 +02:00
|
|
|
if (++count == 1 && res_id)
|
|
|
|
*res_id= (int16) pcat_id->val_int();
|
|
|
|
names->push_back(lname);
|
|
|
|
}
|
|
|
|
end_read_record(&read_record_info);
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_RETURN(count);
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
/*
|
|
|
|
Look for all topics or subcategories of category
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
get_all_items_for_category()
|
|
|
|
thd Thread handler
|
|
|
|
items Table of items
|
|
|
|
pfname Field "name" in items
|
|
|
|
select "where" part of query..
|
|
|
|
res list of finded names
|
|
|
|
*/
|
|
|
|
|
|
|
|
void get_all_items_for_category(THD *thd, TABLE *items, Field *pfname,
|
|
|
|
SQL_SELECT *select, List<String> *res)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("get_all_items_for_category");
|
|
|
|
|
|
|
|
READ_RECORD read_record_info;
|
|
|
|
init_read_record(&read_record_info, thd, items, select,1,0);
|
|
|
|
while (!read_record_info.read_record(&read_record_info))
|
|
|
|
{
|
2004-06-23 12:29:05 +02:00
|
|
|
if (!select->cond->val_int())
|
2003-05-29 23:47:31 +02:00
|
|
|
continue;
|
2004-11-08 00:13:54 +01:00
|
|
|
String *name= new (thd->mem_root) String();
|
|
|
|
get_field(thd->mem_root,pfname,name);
|
2003-05-29 23:47:31 +02:00
|
|
|
res->push_back(name);
|
|
|
|
}
|
|
|
|
end_read_record(&read_record_info);
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Send to client answer for help request
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
SYNOPSIS
|
|
|
|
send_answer_1()
|
|
|
|
protocol - protocol for sending
|
|
|
|
s1 - value of column "Name"
|
2003-05-29 23:47:31 +02:00
|
|
|
s2 - value of column "Description"
|
|
|
|
s3 - value of column "Example"
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
Format used:
|
2003-05-29 23:47:31 +02:00
|
|
|
+----------+------------+------------+
|
|
|
|
|name |description |example |
|
|
|
|
+----------+------------+------------+
|
|
|
|
|String(64)|String(1000)|String(1000)|
|
|
|
|
+----------+------------+------------+
|
2003-02-12 20:55:37 +01:00
|
|
|
with exactly one row!
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
1 Writing of head failed
|
|
|
|
-1 Writing of row failed
|
|
|
|
0 Successeful send
|
|
|
|
*/
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
int send_answer_1(Protocol *protocol, String *s1, String *s2, String *s3)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("send_answer_1");
|
|
|
|
List<Item> field_list;
|
2003-05-29 23:47:31 +02:00
|
|
|
field_list.push_back(new Item_empty_string("name",64));
|
|
|
|
field_list.push_back(new Item_empty_string("description",1000));
|
|
|
|
field_list.push_back(new Item_empty_string("example",1000));
|
2004-06-23 12:29:05 +02:00
|
|
|
|
Port of cursors to be pushed into 5.0 tree:
- client side part is simple and may be considered stable
- server side part now just joggles with THD state to save execution
state and has no additional locking wisdom.
Lot's of it are to be rewritten.
include/mysql.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new statement attribute STMT_ATTR_CURSOR_TYPE
- MYSQL_STMT::flags to store statement cursor type
- MYSQL_STMT::server_status to store server status (i. e. if the server
was able to open a cursor for this query).
include/mysql_com.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new COMmand, COM_FETCH, to fetch K rows from read-only cursor.
By design should support scrollable cursors as well.
- a few new server statuses:
SERVER_STATUS_CURSOR_EXISTS is sent by server in reply to COM_EXECUTE,
when cursor was successfully opened for this query
SERVER_STATUS_LAST_ROW_SENT is sent along with the last row to prevent one
more round trip just for finding out that all rows were fetched from
this cursor (this is server mem savier also).
- and finally, all possible values of STMT_ATTR_CURSOR_TYPE,
while now we support only CURSORT_TYPE_NO_CURSOR and
CURSOR_TYPE_READ_ONLY
libmysql/libmysql.c:
Cursor patch to push into the main tree, client library part (considered
stable):
- simple additions to mysql_stmt_fetch implementation to read data
from an opened cursor: we can read up to iteration count rows per
one request; read rows are buffered in the same way as rows of
mysql_stmt_store_result.
- now send stmt->flags to server to let him now if we wish to have
a cursor for this statement.
- support for setting/getting statement cursor type.
libmysqld/examples/Makefile.am:
Testing cursors was originally implemented in C++. Now when these tests
go into client_test, it's time to convert it to C++ as well.
libmysqld/lib_sql.cc:
- cleanup: send_fields flags are now named.
sql/ha_innodb.cc:
- cleanup: send_fields flags are now named.
sql/mysql_priv.h:
- cursors support: declaration for server-side handler of COM_FETCH
sql/protocol.cc:
- cleanup: send_fields flags are now named.
- we can't anymore assert that field_types[field_pos] is sensible:
if we have COM_EXCUTE(stmt1), COM_EXECUTE(stmt2), COM_FETCH(stmt1)
field_types[field_pos] will point to fields of stmt2.
sql/protocol.h:
- cleanup: send_fields flag_s_ are now named.
sql/protocol_cursor.cc:
- cleanup: send_fields flags are now named.
sql/repl_failsafe.cc:
- cleanup: send_fields flags are now named.
sql/slave.cc:
- cleanup: send_fields flags are now named.
sql/sp.cc:
- cleanup: send_fields flags are now named.
sql/sp_head.cc:
- cleanup: send_fields flags are now named.
sql/sql_acl.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.h:
- cleanup: send_fields flags are now named.
sql/sql_error.cc:
- cleanup: send_fields flags are now named.
sql/sql_handler.cc:
- cleanup: send_fields flags are now named.
sql/sql_help.cc:
- cleanup: send_fields flags are now named.
sql/sql_parse.cc:
Server side support for cursors:
- handle COM_FETCH
- enforce assumption that whenever we free thd->free_list,
we reset it to zero. This way it's much easier to handle free_list
in prepared statements implementation.
sql/sql_prepare.cc:
Server side support for cursors:
- implementation of mysql_stmt_fetch (fetch some rows from open cursor).
- management of cursors memory is quite tricky now.
- execute_stmt can't be reused anymore in mysql_stmt_execute and
mysql_sql_stmt_execute
sql/sql_repl.cc:
- cleanup: send_fields flags are now named.
sql/sql_select.cc:
Server side support for cursors:
- implementation of Cursor::open, Cursor::fetch (buggy when it comes to
non-equi joins), cursor cleanups.
- -4 -3 -0 constants indicating return value of sub_select and end_send are
to be renamed to something more readable:
it turned out to be not so simple, so it should come with the other patch.
sql/sql_select.h:
Server side support for cursors:
- declaration of Cursor class.
- JOIN::fetch_limit contains runtime value of rows fetched via cursor.
sql/sql_show.cc:
- cleanup: send_fields flags are now named.
sql/sql_table.cc:
- cleanup: send_fields flags are now named.
sql/sql_union.cc:
- if there was a cursor, don't cleanup unit: we'll need it to fetch
the rest of the rows.
tests/Makefile.am:
Now client_test is in C++.
tests/client_test.cc:
A few elementary tests for cursors.
BitKeeper/etc/ignore:
Added libmysqld/examples/client_test.cc to the ignore list
2004-08-03 12:32:21 +02:00
|
|
|
if (protocol->send_fields(&field_list,
|
|
|
|
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
2002-10-28 14:44:19 +01:00
|
|
|
DBUG_RETURN(1);
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2002-12-11 08:17:51 +01:00
|
|
|
protocol->prepare_for_resend();
|
2003-05-29 23:47:31 +02:00
|
|
|
protocol->store(s1);
|
|
|
|
protocol->store(s2);
|
|
|
|
protocol->store(s3);
|
2002-12-11 08:17:51 +01:00
|
|
|
if (protocol->write())
|
2002-10-28 14:44:19 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-12-11 08:17:51 +01:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/*
|
|
|
|
Send to client help header
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
send_header_2()
|
2003-05-29 23:47:31 +02:00
|
|
|
protocol - protocol for sending
|
|
|
|
is_it_category - need column 'source_category_name'
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
IMPLEMENTATION
|
2003-05-29 23:47:31 +02:00
|
|
|
+- -+
|
|
|
|
|+-------------------- | +----------+--------------+
|
|
|
|
||source_category_name | |name |is_it_category|
|
|
|
|
|+-------------------- | +----------+--------------+
|
|
|
|
||String(64) | |String(64)|String(1) |
|
|
|
|
|+-------------------- | +----------+--------------+
|
|
|
|
+- -+
|
2003-02-12 20:55:37 +01:00
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
result of protocol->send_fields
|
|
|
|
*/
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
int send_header_2(Protocol *protocol, bool for_category)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
DBUG_ENTER("send_header_2");
|
2002-10-28 14:44:19 +01:00
|
|
|
List<Item> field_list;
|
2003-05-29 23:47:31 +02:00
|
|
|
if (for_category)
|
|
|
|
field_list.push_back(new Item_empty_string("source_category_name",64));
|
|
|
|
field_list.push_back(new Item_empty_string("name",64));
|
|
|
|
field_list.push_back(new Item_empty_string("is_it_category",1));
|
Port of cursors to be pushed into 5.0 tree:
- client side part is simple and may be considered stable
- server side part now just joggles with THD state to save execution
state and has no additional locking wisdom.
Lot's of it are to be rewritten.
include/mysql.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new statement attribute STMT_ATTR_CURSOR_TYPE
- MYSQL_STMT::flags to store statement cursor type
- MYSQL_STMT::server_status to store server status (i. e. if the server
was able to open a cursor for this query).
include/mysql_com.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new COMmand, COM_FETCH, to fetch K rows from read-only cursor.
By design should support scrollable cursors as well.
- a few new server statuses:
SERVER_STATUS_CURSOR_EXISTS is sent by server in reply to COM_EXECUTE,
when cursor was successfully opened for this query
SERVER_STATUS_LAST_ROW_SENT is sent along with the last row to prevent one
more round trip just for finding out that all rows were fetched from
this cursor (this is server mem savier also).
- and finally, all possible values of STMT_ATTR_CURSOR_TYPE,
while now we support only CURSORT_TYPE_NO_CURSOR and
CURSOR_TYPE_READ_ONLY
libmysql/libmysql.c:
Cursor patch to push into the main tree, client library part (considered
stable):
- simple additions to mysql_stmt_fetch implementation to read data
from an opened cursor: we can read up to iteration count rows per
one request; read rows are buffered in the same way as rows of
mysql_stmt_store_result.
- now send stmt->flags to server to let him now if we wish to have
a cursor for this statement.
- support for setting/getting statement cursor type.
libmysqld/examples/Makefile.am:
Testing cursors was originally implemented in C++. Now when these tests
go into client_test, it's time to convert it to C++ as well.
libmysqld/lib_sql.cc:
- cleanup: send_fields flags are now named.
sql/ha_innodb.cc:
- cleanup: send_fields flags are now named.
sql/mysql_priv.h:
- cursors support: declaration for server-side handler of COM_FETCH
sql/protocol.cc:
- cleanup: send_fields flags are now named.
- we can't anymore assert that field_types[field_pos] is sensible:
if we have COM_EXCUTE(stmt1), COM_EXECUTE(stmt2), COM_FETCH(stmt1)
field_types[field_pos] will point to fields of stmt2.
sql/protocol.h:
- cleanup: send_fields flag_s_ are now named.
sql/protocol_cursor.cc:
- cleanup: send_fields flags are now named.
sql/repl_failsafe.cc:
- cleanup: send_fields flags are now named.
sql/slave.cc:
- cleanup: send_fields flags are now named.
sql/sp.cc:
- cleanup: send_fields flags are now named.
sql/sp_head.cc:
- cleanup: send_fields flags are now named.
sql/sql_acl.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.h:
- cleanup: send_fields flags are now named.
sql/sql_error.cc:
- cleanup: send_fields flags are now named.
sql/sql_handler.cc:
- cleanup: send_fields flags are now named.
sql/sql_help.cc:
- cleanup: send_fields flags are now named.
sql/sql_parse.cc:
Server side support for cursors:
- handle COM_FETCH
- enforce assumption that whenever we free thd->free_list,
we reset it to zero. This way it's much easier to handle free_list
in prepared statements implementation.
sql/sql_prepare.cc:
Server side support for cursors:
- implementation of mysql_stmt_fetch (fetch some rows from open cursor).
- management of cursors memory is quite tricky now.
- execute_stmt can't be reused anymore in mysql_stmt_execute and
mysql_sql_stmt_execute
sql/sql_repl.cc:
- cleanup: send_fields flags are now named.
sql/sql_select.cc:
Server side support for cursors:
- implementation of Cursor::open, Cursor::fetch (buggy when it comes to
non-equi joins), cursor cleanups.
- -4 -3 -0 constants indicating return value of sub_select and end_send are
to be renamed to something more readable:
it turned out to be not so simple, so it should come with the other patch.
sql/sql_select.h:
Server side support for cursors:
- declaration of Cursor class.
- JOIN::fetch_limit contains runtime value of rows fetched via cursor.
sql/sql_show.cc:
- cleanup: send_fields flags are now named.
sql/sql_table.cc:
- cleanup: send_fields flags are now named.
sql/sql_union.cc:
- if there was a cursor, don't cleanup unit: we'll need it to fetch
the rest of the rows.
tests/Makefile.am:
Now client_test is in C++.
tests/client_test.cc:
A few elementary tests for cursors.
BitKeeper/etc/ignore:
Added libmysqld/examples/client_test.cc to the ignore list
2004-08-03 12:32:21 +02:00
|
|
|
DBUG_RETURN(protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
|
|
|
|
Protocol::SEND_EOF));
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
/*
|
|
|
|
strcmp for using in qsort
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
strptrcmp()
|
|
|
|
ptr1 (const void*)&str1
|
|
|
|
ptr2 (const void*)&str2
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
same as strcmp
|
|
|
|
*/
|
|
|
|
|
2003-11-28 11:18:13 +01:00
|
|
|
extern "C" int string_ptr_cmp(const void* ptr1, const void* ptr2)
|
2003-05-29 23:47:31 +02:00
|
|
|
{
|
|
|
|
String *str1= *(String**)ptr1;
|
|
|
|
String *str2= *(String**)ptr2;
|
|
|
|
return strcmp(str1->c_ptr(),str2->c_ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Send to client rows in format:
|
|
|
|
column1 : <name>
|
|
|
|
column2 : <is_it_category>
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
send_variant_2_list()
|
|
|
|
protocol Protocol for sending
|
2004-06-23 12:29:05 +02:00
|
|
|
names List of names
|
2003-05-29 23:47:31 +02:00
|
|
|
cat Value of the column <is_it_category>
|
|
|
|
source_name name of category for all items..
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
-1 Writing fail
|
|
|
|
0 Data was successefully send
|
|
|
|
*/
|
|
|
|
|
2004-06-23 12:29:05 +02:00
|
|
|
int send_variant_2_list(MEM_ROOT *mem_root, Protocol *protocol,
|
|
|
|
List<String> *names,
|
2003-05-29 23:47:31 +02:00
|
|
|
const char *cat, String *source_name)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("send_variant_2_list");
|
|
|
|
|
|
|
|
String **pointers= (String**)alloc_root(mem_root,
|
|
|
|
sizeof(String*)*names->elements);
|
2003-06-05 22:19:54 +02:00
|
|
|
String **pos;
|
|
|
|
String **end= pointers + names->elements;
|
2003-05-29 23:47:31 +02:00
|
|
|
|
|
|
|
List_iterator<String> it(*names);
|
2003-06-24 11:10:35 +02:00
|
|
|
for (pos= pointers; pos!=end; (*pos++= it++));
|
2003-05-29 23:47:31 +02:00
|
|
|
|
|
|
|
qsort(pointers,names->elements,sizeof(String*),string_ptr_cmp);
|
|
|
|
|
2003-06-04 05:59:32 +02:00
|
|
|
for (pos= pointers; pos!=end; pos++)
|
2003-05-29 23:47:31 +02:00
|
|
|
{
|
|
|
|
protocol->prepare_for_resend();
|
|
|
|
if (source_name)
|
|
|
|
protocol->store(source_name);
|
|
|
|
protocol->store(*pos);
|
|
|
|
protocol->store(cat,1,&my_charset_latin1);
|
|
|
|
if (protocol->write())
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Prepare simple SQL_SELECT table.* WHERE <Item>
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
prepare_simple_select()
|
|
|
|
thd Thread handler
|
|
|
|
cond WHERE part of select
|
|
|
|
table goal table
|
|
|
|
|
|
|
|
error code of error (out)
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
RETURN VALUES
|
2004-06-23 12:29:05 +02:00
|
|
|
# created SQL_SELECT
|
2003-05-29 23:47:31 +02:00
|
|
|
*/
|
|
|
|
|
2005-07-01 06:05:42 +02:00
|
|
|
SQL_SELECT *prepare_simple_select(THD *thd, Item *cond,
|
2003-05-29 23:47:31 +02:00
|
|
|
TABLE *table, int *error)
|
|
|
|
{
|
2004-12-14 01:36:19 +01:00
|
|
|
if (!cond->fixed)
|
2005-07-01 06:05:42 +02:00
|
|
|
cond->fix_fields(thd, &cond); // can never fail
|
2005-01-26 13:02:19 +01:00
|
|
|
|
|
|
|
/* Assume that no indexes cover all required fields */
|
|
|
|
table->used_keys.clear_all();
|
|
|
|
|
2005-03-16 15:11:01 +01:00
|
|
|
SQL_SELECT *res= make_select(table, 0, 0, cond, 0, error);
|
2005-01-26 12:11:55 +01:00
|
|
|
if (*error || (res && res->check_quick(thd, 0, HA_POS_ERROR)) ||
|
2006-01-03 17:54:54 +01:00
|
|
|
(res && res->quick && res->quick->reset()))
|
2004-06-23 12:29:05 +02:00
|
|
|
{
|
|
|
|
delete res;
|
|
|
|
res=0;
|
|
|
|
}
|
|
|
|
return res;
|
2003-05-29 23:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Prepare simple SQL_SELECT table.* WHERE table.name LIKE mask
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
prepare_select_for_name()
|
|
|
|
thd Thread handler
|
|
|
|
mask mask for compare with name
|
|
|
|
mlen length of mask
|
|
|
|
tables list of tables, used in WHERE
|
|
|
|
table goal table
|
|
|
|
pfname field "name" in table
|
|
|
|
|
|
|
|
error code of error (out)
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-05-29 23:47:31 +02:00
|
|
|
RETURN VALUES
|
2004-06-23 12:29:05 +02:00
|
|
|
# created SQL_SELECT
|
2003-05-29 23:47:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen,
|
|
|
|
TABLE_LIST *tables, TABLE *table,
|
|
|
|
Field *pfname, int *error)
|
|
|
|
{
|
2004-03-20 12:36:26 +01:00
|
|
|
Item *cond= new Item_func_like(new Item_field(pfname),
|
2003-05-29 23:47:31 +02:00
|
|
|
new Item_string(mask,mlen,pfname->charset()),
|
2005-10-21 03:01:52 +02:00
|
|
|
new Item_string("\\",1,&my_charset_latin1),
|
|
|
|
FALSE);
|
2003-10-15 21:40:36 +02:00
|
|
|
if (thd->is_fatal_error)
|
|
|
|
return 0; // OOM
|
2005-07-01 06:05:42 +02:00
|
|
|
return prepare_simple_select(thd, cond, table, error);
|
2003-05-29 23:47:31 +02:00
|
|
|
}
|
2002-12-11 08:17:51 +01:00
|
|
|
|
2003-06-24 11:10:35 +02:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
/*
|
|
|
|
Server-side function 'help'
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
mysqld_help()
|
|
|
|
thd Thread handler
|
|
|
|
|
|
|
|
RETURN VALUES
|
2004-10-20 03:04:37 +02:00
|
|
|
FALSE Success
|
|
|
|
TRUE Error and send_error already commited
|
2003-02-12 20:55:37 +01:00
|
|
|
*/
|
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysqld_help(THD *thd, const char *mask)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2002-12-11 08:17:51 +01:00
|
|
|
Protocol *protocol= thd->protocol;
|
2004-06-23 12:29:05 +02:00
|
|
|
SQL_SELECT *select;
|
2003-02-12 20:55:37 +01:00
|
|
|
st_find_field used_fields[array_elements(init_used_fields)];
|
2004-09-14 18:28:29 +02:00
|
|
|
TABLE_LIST *leaves= 0;
|
2003-05-29 23:47:31 +02:00
|
|
|
TABLE_LIST tables[4];
|
2005-08-18 02:12:42 +02:00
|
|
|
List<String> topics_list, categories_list, subcategories_list;
|
|
|
|
String name, description, example;
|
|
|
|
int count_topics, count_categories, error;
|
|
|
|
uint mlen= strlen(mask);
|
|
|
|
size_t i;
|
|
|
|
MEM_ROOT *mem_root= thd->mem_root;
|
|
|
|
DBUG_ENTER("mysqld_help");
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
bzero((gptr)tables,sizeof(tables));
|
2005-01-06 12:00:13 +01:00
|
|
|
tables[0].alias= tables[0].table_name= (char*) "help_topic";
|
2003-02-12 20:55:37 +01:00
|
|
|
tables[0].lock_type= TL_READ;
|
2005-08-18 02:12:42 +02:00
|
|
|
tables[0].next_global= tables[0].next_local=
|
|
|
|
tables[0].next_name_resolution_table= &tables[1];
|
2005-01-06 12:00:13 +01:00
|
|
|
tables[1].alias= tables[1].table_name= (char*) "help_category";
|
2003-02-12 20:55:37 +01:00
|
|
|
tables[1].lock_type= TL_READ;
|
2005-08-18 02:12:42 +02:00
|
|
|
tables[1].next_global= tables[1].next_local=
|
|
|
|
tables[1].next_name_resolution_table= &tables[2];
|
2005-01-06 12:00:13 +01:00
|
|
|
tables[2].alias= tables[2].table_name= (char*) "help_relation";
|
2003-02-12 20:55:37 +01:00
|
|
|
tables[2].lock_type= TL_READ;
|
2005-08-18 02:12:42 +02:00
|
|
|
tables[2].next_global= tables[2].next_local=
|
|
|
|
tables[2].next_name_resolution_table= &tables[3];
|
2005-01-06 12:00:13 +01:00
|
|
|
tables[3].alias= tables[3].table_name= (char*) "help_keyword";
|
2003-05-29 23:47:31 +02:00
|
|
|
tables[3].lock_type= TL_READ;
|
2004-04-04 02:05:44 +02:00
|
|
|
tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql";
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
if (open_and_lock_tables(thd, tables))
|
|
|
|
goto error;
|
2004-07-16 00:15:55 +02:00
|
|
|
/*
|
|
|
|
Init tables and fields to be usable from items
|
|
|
|
tables do not contain VIEWs => we can pass 0 as conds
|
|
|
|
*/
|
2005-07-01 06:05:42 +02:00
|
|
|
setup_tables(thd, &thd->lex->select_lex.context,
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
&thd->lex->select_lex.top_join_list,
|
2005-07-01 06:05:42 +02:00
|
|
|
tables, 0, &leaves, FALSE);
|
2004-06-23 12:29:05 +02:00
|
|
|
memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields));
|
2003-02-12 20:55:37 +01:00
|
|
|
if (init_fields(thd, tables, used_fields, array_elements(used_fields)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2003-06-04 05:59:32 +02:00
|
|
|
for (i=0; i<sizeof(tables)/sizeof(TABLE_LIST); i++)
|
2003-05-29 23:47:31 +02:00
|
|
|
tables[i].table->file->init_table_handle_for_HANDLER();
|
2004-06-23 12:29:05 +02:00
|
|
|
|
|
|
|
if (!(select=
|
2003-05-29 23:47:31 +02:00
|
|
|
prepare_select_for_name(thd,mask,mlen,tables,tables[0].table,
|
2004-06-23 12:29:05 +02:00
|
|
|
used_fields[help_topic_name].field,&error)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2003-02-12 20:55:37 +01:00
|
|
|
|
2004-06-23 12:29:05 +02:00
|
|
|
count_topics= search_topics(thd,tables[0].table,used_fields,
|
|
|
|
select,&topics_list,
|
2003-05-29 23:47:31 +02:00
|
|
|
&name, &description, &example);
|
2004-06-23 12:29:05 +02:00
|
|
|
delete select;
|
2003-05-29 23:47:31 +02:00
|
|
|
|
|
|
|
if (count_topics == 0)
|
2004-06-23 12:29:05 +02:00
|
|
|
{
|
|
|
|
int key_id;
|
|
|
|
if (!(select=
|
|
|
|
prepare_select_for_name(thd,mask,mlen,tables,tables[3].table,
|
|
|
|
used_fields[help_keyword_name].field,&error)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
|
|
|
|
2004-06-23 12:29:05 +02:00
|
|
|
count_topics=search_keyword(thd,tables[3].table,used_fields,select,&key_id);
|
|
|
|
delete select;
|
|
|
|
count_topics= (count_topics != 1) ? 0 :
|
|
|
|
get_topics_for_keyword(thd,tables[0].table,tables[2].table,
|
|
|
|
used_fields,key_id,&topics_list,&name,
|
|
|
|
&description,&example);
|
|
|
|
}
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
if (count_topics == 0)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
|
|
|
int16 category_id;
|
2003-05-29 23:47:31 +02:00
|
|
|
Field *cat_cat_id= used_fields[help_category_parent_category_id].field;
|
2004-06-23 12:29:05 +02:00
|
|
|
if (!(select=
|
|
|
|
prepare_select_for_name(thd,mask,mlen,tables,tables[1].table,
|
|
|
|
used_fields[help_category_name].field,&error)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2004-06-23 12:29:05 +02:00
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
count_categories= search_categories(thd, tables[1].table, used_fields,
|
2004-06-23 12:29:05 +02:00
|
|
|
select,
|
2003-05-29 23:47:31 +02:00
|
|
|
&categories_list,&category_id);
|
2004-06-23 12:29:05 +02:00
|
|
|
delete select;
|
2003-05-29 23:47:31 +02:00
|
|
|
if (!count_categories)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2004-03-30 01:32:41 +02:00
|
|
|
if (send_header_2(protocol,FALSE))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2003-05-29 23:47:31 +02:00
|
|
|
}
|
|
|
|
else if (count_categories > 1)
|
|
|
|
{
|
2004-03-30 01:32:41 +02:00
|
|
|
if (send_header_2(protocol,FALSE) ||
|
2003-05-29 23:47:31 +02:00
|
|
|
send_variant_2_list(mem_root,protocol,&categories_list,"Y",0))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2003-05-29 23:47:31 +02:00
|
|
|
else
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
Field *topic_cat_id= used_fields[help_topic_help_category_id].field;
|
2004-03-18 14:14:36 +01:00
|
|
|
Item *cond_topic_by_cat=
|
2004-03-20 12:36:26 +01:00
|
|
|
new Item_func_equal(new Item_field(topic_cat_id),
|
2004-03-18 14:14:36 +01:00
|
|
|
new Item_int((int32)category_id));
|
|
|
|
Item *cond_cat_by_cat=
|
2004-03-20 12:36:26 +01:00
|
|
|
new Item_func_equal(new Item_field(cat_cat_id),
|
2004-03-18 14:14:36 +01:00
|
|
|
new Item_int((int32)category_id));
|
2005-07-01 06:05:42 +02:00
|
|
|
if (!(select= prepare_simple_select(thd, cond_topic_by_cat,
|
|
|
|
tables[0].table, &error)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2003-05-29 23:47:31 +02:00
|
|
|
get_all_items_for_category(thd,tables[0].table,
|
|
|
|
used_fields[help_topic_name].field,
|
2004-06-23 12:29:05 +02:00
|
|
|
select,&topics_list);
|
|
|
|
delete select;
|
2005-07-01 06:05:42 +02:00
|
|
|
if (!(select= prepare_simple_select(thd, cond_cat_by_cat,
|
|
|
|
tables[1].table, &error)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2003-05-29 23:47:31 +02:00
|
|
|
get_all_items_for_category(thd,tables[1].table,
|
|
|
|
used_fields[help_category_name].field,
|
2004-06-23 12:29:05 +02:00
|
|
|
select,&subcategories_list);
|
|
|
|
delete select;
|
2003-05-29 23:47:31 +02:00
|
|
|
String *cat= categories_list.head();
|
true,false -> TRUE, FALSE
Simple fixes/optimization of things discovered during review of new pushed code
include/my_sys.h:
Ensure that clear_alloc_root() interacts correctly with alloc_root_inited()
mysys/hash.c:
More comments
Simple optimization (merge identical code)
mysys/my_bitmap.c:
Change inline -> static inline
sql/examples/ha_archive.cc:
Fixed compiler warning
sql/ha_ndbcluster.cc:
true,false -> TRUE, FALSE
Change if (false) -> #ifdef NOT_USED
sql/ha_ndbcluster.h:
true,false -> TRUE, FALSE
sql/handler.cc:
More comments
Remove not needed initializations.
#ifdef not used code
sql/item_cmpfunc.h:
true,false -> TRUE, FALSE
sql/item_strfunc.cc:
Move local variables to function beginning
Remove wrong comments
sql/log_event.h:
true,false -> TRUE, FALSE
sql/sql_base.cc:
true,false -> TRUE, FALSE
More comments
sql/sql_help.cc:
true,false -> TRUE, FALSE
sql/sql_lex.cc:
Simple optimization of new code
sql/sql_parse.cc:
true,false -> TRUE, FALSE
sql/sql_prepare.cc:
true,false -> TRUE, FALSE
sql/sql_table.cc:
true,false -> TRUE, FALSE
sql/sql_yacc.yy:
true,false -> TRUE, FALSE
2004-10-14 17:03:46 +02:00
|
|
|
if (send_header_2(protocol, TRUE) ||
|
2003-05-29 23:47:31 +02:00
|
|
|
send_variant_2_list(mem_root,protocol,&topics_list, "N",cat) ||
|
|
|
|
send_variant_2_list(mem_root,protocol,&subcategories_list,"Y",cat))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
2003-02-12 20:55:37 +01:00
|
|
|
else if (count_topics == 1)
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-05-29 23:47:31 +02:00
|
|
|
if (send_answer_1(protocol,&name,&description,&example))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2003-02-12 20:55:37 +01:00
|
|
|
else
|
2002-10-28 14:44:19 +01:00
|
|
|
{
|
2003-02-12 20:55:37 +01:00
|
|
|
/* First send header and functions */
|
2004-03-30 01:32:41 +02:00
|
|
|
if (send_header_2(protocol, FALSE) ||
|
2003-05-29 23:47:31 +02:00
|
|
|
send_variant_2_list(mem_root,protocol, &topics_list, "N", 0))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2004-06-23 12:29:05 +02:00
|
|
|
if (!(select=
|
|
|
|
prepare_select_for_name(thd,mask,mlen,tables,tables[1].table,
|
|
|
|
used_fields[help_category_name].field,&error)))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2004-06-23 12:29:05 +02:00
|
|
|
search_categories(thd, tables[1].table, used_fields,
|
|
|
|
select,&categories_list, 0);
|
|
|
|
delete select;
|
2003-02-12 20:55:37 +01:00
|
|
|
/* Then send categories */
|
2003-05-29 23:47:31 +02:00
|
|
|
if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0))
|
2004-10-20 03:04:37 +02:00
|
|
|
goto error;
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
|
|
|
send_eof(thd);
|
2003-06-24 11:10:35 +02:00
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
error:
|
|
|
|
DBUG_RETURN(TRUE);
|
2002-10-28 14:44:19 +01:00
|
|
|
}
|
2003-06-24 11:10:35 +02:00
|
|
|
|