mariadb/sql/sql_olap.cc

186 lines
5.9 KiB
C++
Raw Normal View History

/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 */
Removed wrong implementation of CUBE/ROLLUP Fixed bugfix of INSERT ... SET db_name.table_name.column_name Changed locking to external-locking Fix client hangup for some invalid SQL queries. Docs/manual.texi: Changelog & recent incompatible changes to 4.0.3 include/mysqld_error.h: New error messages myisam/ft_boolean_search.c: Removed compiler warning myisam/mi_check.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_dynrec.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_extra.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_key.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_open.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_packrec.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/myisamdef.h: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/sort.c: Fixed uninitialized variable mysql-test/r/insert_set.result: Change test case to use database foo mysql-test/r/union.result: Test wrong usage of union mysql-test/t/insert_set.test: Test bug in insert mysql-test/t/union.test: Test wrong usage of union sql/item.h: Indentation cleanup sql/item_cmpfunc.h: Indentation cleanup sql/item_func.h: Indentation cleanup sql/item_strfunc.h: Indentation cleanup sql/item_sum.h: Indentation cleanup sql/item_timefunc.h: Indentation cleanup sql/item_uniq.h: Indentation cleanup sql/mysql_priv.h: Fix that we always generate an error message when calling YYABORT sql/mysqld.cc: Changed command line arguments regarding locking to always use --external-locking Disable external locking by default sql/procedure.h: Cleanup sql/set_var.cc: change locking -> external_locking sql/share/czech/errmsg.txt: New error messages sql/share/danish/errmsg.txt: New error messages sql/share/dutch/errmsg.txt: New error messages sql/share/english/errmsg.txt: New error messages sql/share/estonian/errmsg.txt: New error messages sql/share/french/errmsg.txt: New error messages sql/share/german/errmsg.txt: New error messages sql/share/greek/errmsg.txt: New error messages sql/share/hungarian/errmsg.txt: New error messages sql/share/italian/errmsg.txt: New error messages sql/share/japanese/errmsg.txt: New error messages sql/share/korean/errmsg.txt: New error messages mysql-test/r/olap.result: Removed CUBE/ROLLUP mysql-test/t/olap.test: Removed CUBE/ROLLUP sql/share/norwegian-ny/errmsg.txt: New error messages sql/share/norwegian/errmsg.txt: New error messages sql/share/polish/errmsg.txt: New error messages sql/share/portuguese/errmsg.txt: New error messages sql/share/romanian/errmsg.txt: New error messages sql/share/russian/errmsg.txt: New error messages sql/share/slovak/errmsg.txt: New error messages sql/share/spanish/errmsg.txt: New error messages sql/share/swedish/errmsg.txt: New error messages sql/share/ukrainian/errmsg.txt: New error messages sql/sql_base.cc: Removed wrong patch for INSERT... sql/sql_insert.cc: Fix bug in INSERT ... SET db_name.table_name.column_name sql/sql_lex.h: Changed NON_EXISTIONG_ONE -> UNSPECIFIED_OLAP_TYPE sql/sql_olap.cc: Removed wrong implementation of CUBE/ROLLUP sql/sql_parse.cc: Removed wrong implementation of CUBE/ROLLUP Added function to give better error messages sql/sql_select.cc: Removed wrong implementation of CUBE/ROLLUP sql/sql_union.cc: Added comment sql/sql_yacc.yy: Fix that we always generate an error message when calling YYABORT
2002-07-24 18:55:08 +02:00
/*
OLAP implementation by Sinisa Milivojevic <sinisa@mysql.com>
Inspired by code submitted by Srilakshmi <lakshmi@gdit.iiit.net>
The ROLLUP code in this file has to be complitely rewritten as it's
not good enough to satisfy the goals of MySQL.
In 4.1 we will replace this with a working, superior implementation
of ROLLUP.
*/
#ifdef DISABLED_UNTIL_REWRITTEN_IN_4_1
#ifdef __GNUC__
#pragma implementation // gcc: Class implementation
#endif
#include "mysql_priv.h"
#include "sql_select.h"
/****************************************************************************
Functions that recursively actually creates new SELECT's
Returns 0 if OK, 1 if error, -1 if error already printed to client
****************************************************************************/
static int make_new_olap_select(LEX *lex, SELECT_LEX *select_lex, List<Item> new_fields)
{
THD *thd=current_thd;
Item *item, *new_item;
Item_null *constant= new Item_null("ALL");
SELECT_LEX *new_select = (SELECT_LEX *) thd->memdup((char*) select_lex, sizeof(*select_lex));
if (!new_select)
return 1;
lex->last_selects->next=new_select;
new_select->linkage=OLAP_TYPE;
new_select->olap=NON_EXISTING_ONE;
new_select->group_list.elements=0;
new_select->group_list.first=(byte *)0;
new_select->group_list.next=(byte **)&new_select->group_list.first;
List<Item> privlist;
List_iterator<Item> list_it(select_lex->item_list);
List_iterator<Item> new_it(new_fields);
while ((item=list_it++))
{
bool not_found= TRUE;
if (item->type()==Item::FIELD_ITEM)
{
Item_field *iif = (Item_field *)item;
new_it.rewind();
while ((new_item=new_it++))
{
if (new_item->type()==Item::FIELD_ITEM &&
!strcmp(((Item_field*)new_item)->table_name,iif->table_name) &&
!strcmp(((Item_field*)new_item)->field_name,iif->field_name))
{
New multi-table-update code New (simpler) internal timestamp handling. More debuging to heap tables. Small cleanups to multi-table-delete false -> 0 and true -> 1 (We should use TRUE and FALSE) heap/_check.c: Added checking of rows heap/hp_delete.c: Extra debugging heap/hp_scan.c: Extra debugging heap/hp_update.c: Extra debugging heap/hp_write.c: Extra debugging include/my_base.h: Added option to disable row cache when using updates isam/extra.c: Added option to disable row cache when using updates myisam/mi_check.c: Comment cleanup myisam/mi_extra.c: Added option to disable row cache when using updates myisam/sort.c: Indentaion cleanups myisammrg/myrg_extra.c: Added option to disable row cache when using updates mysql-test/r/multi_update.result: Updated results mysql-test/t/multi_update.test: Cleanup up to only use table names t1, t2,... mysys/mf_iocache.c: Safety fix sql/item_cmpfunc.cc: change true-> 1 and false -> 0 sql/mysql_priv.h: Cleaned up SQL_LIST handling sql/sql_base.cc: Fixed grant checking if SELECT tablename.* sql/sql_class.h: Cleaned up multi-table-update sql/sql_delete.cc: Fixed OPTION_SAFE_UPDATE checking in multi-table-delete. Fixed query-cache invalidation in multi-table-delete sql/sql_insert.cc: cleaned up timestamp handling sql/sql_olap.cc: false -> 0 sql/sql_parse.cc: Optimized some list handling. Moved multi-table-update to sql_update.cc sql/sql_select.cc: More comments Fixed create_tmp_table for multi-table-update sql/sql_select.h: New prototypes sql/sql_union.cc: false -> 0 Cleaned up timestamp handling sql/sql_update.cc: New multi-update-table code sql/sql_yacc.yy: false -> 0, true -> 1 Optimized some list handling sql/table.h: Added union for temporary values. Made shared int to be able to store counters. sql/uniques.cc: Indentation cleanup
2002-11-29 15:40:18 +01:00
not_found= 0;
((Item_field*)new_item)->db_name=iif->db_name;
Item_field *new_one=new Item_field(iif->db_name, iif->table_name, iif->field_name);
privlist.push_back(new_one);
if (add_to_list(new_select->group_list,new_one,1))
return 1;
break;
}
}
}
if (not_found)
{
if (item->type() == Item::FIELD_ITEM)
privlist.push_back(constant);
else
privlist.push_back((Item*)thd->memdup((char *)item,item->size_of()));
}
}
new_select->item_list=privlist;
lex->last_selects = new_select;
return 0;
}
/****************************************************************************
Functions that recursively creates combinations of queries for OLAP
Returns 0 if OK, 1 if error, -1 if error already printed to client
****************************************************************************/
static int olap_combos(List<Item> old_fields, List<Item> new_fields, Item *item, LEX *lex,
SELECT_LEX *select_lex, int position, int selection, int num_fields,
int num_new_fields)
{
int sl_return = 0;
if (position == num_new_fields)
{
if (item)
new_fields.push_front(item);
sl_return = make_new_olap_select(lex, select_lex, new_fields);
}
else
{
if (item)
new_fields.push_front(item);
while ((num_fields - num_new_fields >= selection - position) && !sl_return)
{
item = old_fields.pop();
sl_return = olap_combos(old_fields, new_fields, item, lex, select_lex, position+1, ++selection, num_fields, num_new_fields);
}
}
return sl_return;
}
/****************************************************************************
Top level function for converting OLAP clauses to multiple selects
This is also a place where clauses treatment depends on OLAP type
Returns 0 if OK, 1 if error, -1 if error already printed to client
****************************************************************************/
int handle_olaps(LEX *lex, SELECT_LEX *select_lex)
{
List<Item> item_list_copy, new_item_list;
item_list_copy.empty();
new_item_list.empty();
int count=select_lex->group_list.elements;
int sl_return=0;
lex->last_selects=select_lex;
for (ORDER *order=(ORDER *)select_lex->group_list.first ; order ; order=order->next)
item_list_copy.push_back(*(order->item));
List<Item> all_fields(select_lex->item_list);
if (setup_tables((TABLE_LIST *)select_lex->table_list.first) ||
fixed subselects with temporary tables (SCRUM) fixed memory leacks mysql-test/r/subselect.result: some changes in subselect tests mysql-test/t/subselect.test: some changes in subselect tests sql/item.cc: some item made copyable methods for creating copy of item list tmp_table_field() splited sql/item.h: some item made copyable methods for creating copy of item list tmp_table_field() splited sql/item_cmpfunc.cc: changed references creation sql/item_cmpfunc.h: changed references creation sql/item_func.cc: some item made copyable methods for creating copy of item list changed references creation sql/item_func.h: some item made copyable methods for creating copy of item list changed references creation tmp_table_field() splited sql/item_subselect.cc: changed references creation sql/item_sum.cc: some item made copyable methods for creating copy of item list sql/item_sum.h: some item made copyable methods for creating copy of item list sql/item_timefunc.h: tmp_table_field() splited sql/item_uniq.h: some item made copyable methods for creating copy of item list sql/mysql_priv.h: fixed subselects with temporary tables sql/sql_base.cc: fixed subselects with temporary tables sql/sql_class.h: fixed subselects with temporary tables sql/sql_delete.cc: fixed subselects with temporary tables sql/sql_derived.cc: fixed subselects with temporary tables sql/sql_do.cc: fixed subselects with temporary tables sql/sql_insert.cc: fixed subselects with temporary tables sql/sql_lex.cc: fixed subselects with temporary tables sql/sql_lex.h: fixed subselects with temporary tables sql/sql_list.h: fixed subselects with temporary tables sql/sql_load.cc: fixed subselects with temporary tables sql/sql_olap.cc: fixed subselects with temporary tables sql/sql_parse.cc: fixed subselects with temporary tables sql/sql_prepare.cc: fixed subselects with temporary tables sql/sql_select.cc: fixed subselects with temporary tables sql/sql_select.h: fixed subselects with temporary tables sql/sql_table.cc: fixed subselects with temporary tables sql/sql_union.cc: fixed subselects with temporary tables sql/sql_update.cc: fixed subselects with temporary tables sql/sql_yacc.yy: fixed subselects with temporary tables
2003-01-25 01:25:52 +01:00
setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first,
select_lex->item_list, 1, &all_fields,1) ||
setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first,
item_list_copy, 1, &all_fields, 1))
return -1;
if (select_lex->olap == CUBE_TYPE)
{
for ( int i=count-1; i>=0 && !sl_return; i--)
sl_return=olap_combos(item_list_copy, new_item_list, (Item *)0, lex, select_lex, 0, 0, count, i);
}
else if (select_lex->olap == ROLLUP_TYPE)
{
for ( int i=count-1; i>=0 && !sl_return; i--)
{
Item *item;
item_list_copy.pop();
List_iterator<Item> it(item_list_copy);
new_item_list.empty();
while ((item = it++))
new_item_list.push_front(item);
sl_return=make_new_olap_select(lex, select_lex, new_item_list);
}
}
else
sl_return=1; // impossible
return sl_return;
}
Removed wrong implementation of CUBE/ROLLUP Fixed bugfix of INSERT ... SET db_name.table_name.column_name Changed locking to external-locking Fix client hangup for some invalid SQL queries. Docs/manual.texi: Changelog & recent incompatible changes to 4.0.3 include/mysqld_error.h: New error messages myisam/ft_boolean_search.c: Removed compiler warning myisam/mi_check.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_dynrec.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_extra.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_key.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_open.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/mi_packrec.c: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/myisamdef.h: Change mi_fix_rec_buff_for_blob to mi_alloc_rec_buff myisam/sort.c: Fixed uninitialized variable mysql-test/r/insert_set.result: Change test case to use database foo mysql-test/r/union.result: Test wrong usage of union mysql-test/t/insert_set.test: Test bug in insert mysql-test/t/union.test: Test wrong usage of union sql/item.h: Indentation cleanup sql/item_cmpfunc.h: Indentation cleanup sql/item_func.h: Indentation cleanup sql/item_strfunc.h: Indentation cleanup sql/item_sum.h: Indentation cleanup sql/item_timefunc.h: Indentation cleanup sql/item_uniq.h: Indentation cleanup sql/mysql_priv.h: Fix that we always generate an error message when calling YYABORT sql/mysqld.cc: Changed command line arguments regarding locking to always use --external-locking Disable external locking by default sql/procedure.h: Cleanup sql/set_var.cc: change locking -> external_locking sql/share/czech/errmsg.txt: New error messages sql/share/danish/errmsg.txt: New error messages sql/share/dutch/errmsg.txt: New error messages sql/share/english/errmsg.txt: New error messages sql/share/estonian/errmsg.txt: New error messages sql/share/french/errmsg.txt: New error messages sql/share/german/errmsg.txt: New error messages sql/share/greek/errmsg.txt: New error messages sql/share/hungarian/errmsg.txt: New error messages sql/share/italian/errmsg.txt: New error messages sql/share/japanese/errmsg.txt: New error messages sql/share/korean/errmsg.txt: New error messages mysql-test/r/olap.result: Removed CUBE/ROLLUP mysql-test/t/olap.test: Removed CUBE/ROLLUP sql/share/norwegian-ny/errmsg.txt: New error messages sql/share/norwegian/errmsg.txt: New error messages sql/share/polish/errmsg.txt: New error messages sql/share/portuguese/errmsg.txt: New error messages sql/share/romanian/errmsg.txt: New error messages sql/share/russian/errmsg.txt: New error messages sql/share/slovak/errmsg.txt: New error messages sql/share/spanish/errmsg.txt: New error messages sql/share/swedish/errmsg.txt: New error messages sql/share/ukrainian/errmsg.txt: New error messages sql/sql_base.cc: Removed wrong patch for INSERT... sql/sql_insert.cc: Fix bug in INSERT ... SET db_name.table_name.column_name sql/sql_lex.h: Changed NON_EXISTIONG_ONE -> UNSPECIFIED_OLAP_TYPE sql/sql_olap.cc: Removed wrong implementation of CUBE/ROLLUP sql/sql_parse.cc: Removed wrong implementation of CUBE/ROLLUP Added function to give better error messages sql/sql_select.cc: Removed wrong implementation of CUBE/ROLLUP sql/sql_union.cc: Added comment sql/sql_yacc.yy: Fix that we always generate an error message when calling YYABORT
2002-07-24 18:55:08 +02:00
#endif /* DISABLED_UNTIL_REWRITTEN_IN_4_1 */