Commit 2e8fb546 authored by Sinisa@sinisa.nasamreza.org's avatar Sinisa@sinisa.nasamreza.org
Browse files

OLAP functionality plus some small bug fixes

parent 4331c705
Loading
Loading
Loading
Loading
+136 −0
Original line number Diff line number Diff line
@@ -49259,6 +49259,12 @@ New client-server protocol for 4.0
@item
Multi-table @code{DELETE}/@code{UPDATE}
@item
derived tables
@item
user resources management
@item
OLAP functionality
@item
The @code{MySQLGUI} client.
@item
Maintainer of @code{MySQL++}.
@@ -49689,8 +49695,138 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@item
Fixed a bug that made the pager option in the mysql client non-functional.
@end itemize
@item
Added OLAP functionality.
Arjen , please add the following text somewhere appropriate in the 
text above:
-------------------------------------------------------------------------
Documentation for OLAP extension
Introduction 
------------
MySQL will first support CUBE and ROLLUP operators from entire OLAP
functionality.  
The  CUBE  and ROLLUP extensions  to  SQL make querying  and reporting
easier  in data warehousing  environments. ROLLUP creates subtotals at
increasing levels of aggregation, from the most detailed up to a grand
total. CUBE  is an extension   similar to  ROLLUP,  enabling a  single
statement to calculate all possible combinations of subtotals.
Syntax: 
------	
The syntax supported by the enhanced mysql for CUBE and ROLLUP
operators.  
CUBE 
---- 
SELECT field1, field2, ... AGGR(fieldn) FROM
table GROUP BY field1, field2 field(n-1) WITH CUBE 
This would generate the aggregates with group bys of all the
combinations of dimensions.
ROLLUP:
-----        
	SELECT field1, field2, ... AGGR(fieldn) FROM table 
	GROUP BY field1, field2 field(n-1) WITH ROLLUP 
Example:
-------
mysql> select * from sales;
+------------+---------------+------+--------+
| product    | country       | year | profit |
+------------+---------------+------+--------+
| Computer   | India         | 2000 |   1200 |
| TV         | United States | 1999 |    150 |
| Calculator | United States | 1999 |     50 |
| Computer   | United States | 1999 |   1500 |
| Computer   | United States | 2000 |   1500 |
| TV         | United States | 2000 |    150 |
| TV         | India         | 2000 |    100 |
| TV         | India         | 2000 |    100 |
| Calculator | United States | 2000 |     75 |
| Calculator | India         | 2000 |     75 |
| TV         | India         | 1999 |    100 |
| Computer   | India         | 1999 |   1200 |
| Computer   | United States | 2000 |   1500 |
| Calculator | United States | 2000 |     75 |
+------------+---------------+------+--------+
14 rows in set (0.00 sec)
 
mysql> Select sales.product, sales.country , sales.year, sum(profit) from 
sales group by product, country, year with cube;
+------------+---------------+------+-------------+
| product    | country       | year | sum(profit) |
+------------+---------------+------+-------------+
| Calculator | India         | 2000 |          75 |
| Calculator | United States | 1999 |          50 |
| Calculator | United States | 2000 |         150 |
| Computer   | India         | 1999 |        1200 |
| Computer   | India         | 2000 |        1200 |
| Computer   | United States | 1999 |        1500 |
| Computer   | United States | 2000 |        3000 |
| TV         | India         | 1999 |         100 |
| TV         | India         | 2000 |         200 |
| TV         | United States | 1999 |         150 |
| TV         | United States | 2000 |         150 |
| ALL        | India         | 1999 |        1300 |
| ALL        | India         | 2000 |        1475 |
| ALL        | United States | 1999 |        1700 |
| ALL        | United States | 2000 |        3300 |
| Calculator | ALL           | 1999 |          50 |
| Calculator | ALL           | 2000 |         225 |
| Computer   | ALL           | 1999 |        2700 |
| Computer   | ALL           | 2000 |        4200 |
| TV         | ALL           | 1999 |         250 |
| TV         | ALL           | 2000 |         350 |
| Calculator | India         | ALL  |          75 |
| Calculator | United States | ALL  |         200 |
| Computer   | India         | ALL  |        2400 |
| Computer   | United States | ALL  |        4500 |
| TV         | India         | ALL  |         300 |
| TV         | United States | ALL  |         300 |
| ALL        | ALL           | 1999 |        3000 |
| ALL        | ALL           | 2000 |        4775 |
| ALL        | India         | ALL  |        2775 |
| ALL        | United States | ALL  |        5000 |
| Calculator | ALL           | ALL  |         275 |
| Computer   | ALL           | ALL  |        6900 |
| TV         | ALL           | ALL  |         600 |
| ALL        | ALL           | ALL  |        7775 |
+------------+---------------+------+-------------+
35 rows in set (0.00 sec)
MySQL supports now CUBE and ROLLUP extensions, with all  functions
that one wishes to use with them.
Those extensions already work in all tested combinations. They work
with UNION's, should work with sub-selects in 4.1 and derived tables. 
TODO
----
For the moment, ORDER and LIMIT are disabled for CUBE and ROLLUP. This
however remains to be added later.
Another feature that has to be added later is grouping of select list
itmes in order to alleviate user errors. For the moment, missing
(hidden) columns are not used at all.
-------------------------------------------------------------------------
@node News-4.0.2, News-4.0.1, News-4.0.3, News-4.0.x
@appendixsubsec Changes in release 4.0.2 (01 July 2002)
+138 −0
Original line number Diff line number Diff line
drop table if exists sales;
create table sales ( product varchar(32), country varchar(32), year int, profit int);
insert into sales  values ( 'Computer', 'India',2000, 1200),
( 'TV', 'United States', 1999, 150),
( 'Calculator', 'United States', 1999,50),
( 'Computer', 'United States', 1999,1500),
( 'Computer', 'United States', 2000,1500),
( 'TV', 'United States', 2000, 150),
( 'TV', 'India', 2000, 100),
( 'TV', 'India', 2000, 100),
( 'Calculator', 'United States', 2000,75),
( 'Calculator', 'India', 2000,75),
( 'TV', 'India', 1999, 100),
( 'Computer', 'India', 1999,1200),
( 'Computer', 'United States', 2000,1500),
( 'Calculator', 'United States', 2000,75);
select product, country , year, sum(profit) from sales group by product, country, year with cube;
product	country	year	sum(profit)
Calculator	India	2000	75
Calculator	United States	1999	50
Calculator	United States	2000	150
Computer	India	1999	1200
Computer	India	2000	1200
Computer	United States	1999	1500
Computer	United States	2000	3000
TV	India	1999	100
TV	India	2000	200
TV	United States	1999	150
TV	United States	2000	150
Calculator	India	0	75
Calculator	United States	0	200
Computer	India	0	2400
Computer	United States	0	4500
TV	India	0	300
TV	United States	0	300
Calculator	ALL	1999	50
Calculator	ALL	2000	225
Computer	ALL	1999	2700
Computer	ALL	2000	4200
TV	ALL	1999	250
TV	ALL	2000	350
ALL	India	1999	1300
ALL	India	2000	1475
ALL	United States	1999	1700
ALL	United States	2000	3300
Calculator	ALL	0	275
Computer	ALL	0	6900
TV	ALL	0	600
ALL	India	0	2775
ALL	United States	0	5000
ALL	ALL	1999	3000
ALL	ALL	2000	4775
ALL	ALL	0	7775
explain select product, country , year, sum(profit) from sales group by product, country, year with cube;
table	type	possible_keys	key	key_len	ref	rows	Extra
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	
select product, country , year, sum(profit) from sales group by product, country, year with rollup;
product	country	year	sum(profit)
Calculator	India	2000	75
Calculator	United States	1999	50
Calculator	United States	2000	150
Computer	India	1999	1200
Computer	India	2000	1200
Computer	United States	1999	1500
Computer	United States	2000	3000
TV	India	1999	100
TV	India	2000	200
TV	United States	1999	150
TV	United States	2000	150
ALL	India	1999	1300
ALL	India	2000	1475
ALL	United States	1999	1700
ALL	United States	2000	3300
ALL	ALL	1999	3000
ALL	ALL	2000	4775
ALL	ALL	0	7775
explain select product, country , year, sum(profit) from sales group by product, country, year with rollup;
table	type	possible_keys	key	key_len	ref	rows	Extra
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	Using temporary; Using filesort
sales	ALL	NULL	NULL	NULL	NULL	14	
select product, country , year, sum(profit) from sales group by product, country, year with cube union all select product, country , year, sum(profit) from sales group by product, country, year with rollup;
product	country	year	sum(profit)
Calculator	India	2000	75
Calculator	United States	1999	50
Calculator	United States	2000	150
Computer	India	1999	1200
Computer	India	2000	1200
Computer	United States	1999	1500
Computer	United States	2000	3000
TV	India	1999	100
TV	India	2000	200
TV	United States	1999	150
TV	United States	2000	150
Calculator	India	0	75
Calculator	United States	0	200
Computer	India	0	2400
Computer	United States	0	4500
TV	India	0	300
TV	United States	0	300
Calculator	ALL	1999	50
Calculator	ALL	2000	225
Computer	ALL	1999	2700
Computer	ALL	2000	4200
TV	ALL	1999	250
TV	ALL	2000	350
ALL	India	1999	1300
ALL	India	2000	1475
ALL	United States	1999	1700
ALL	United States	2000	3300
Calculator	ALL	0	275
Computer	ALL	0	6900
TV	ALL	0	600
ALL	India	0	2775
ALL	United States	0	5000
ALL	ALL	1999	3000
ALL	ALL	2000	4775
ALL	ALL	0	7775
Calculator	India	2000	75
Calculator	United States	1999	50
Calculator	United States	2000	150
Computer	India	1999	1200
Computer	India	2000	1200
Computer	United States	1999	1500
Computer	United States	2000	3000
TV	India	1999	100
TV	India	2000	200
TV	United States	1999	150
TV	United States	2000	150
drop table sales;

mysql-test/t/olap.test

0 → 100644
+22 −0
Original line number Diff line number Diff line
drop table if exists sales;
create table sales ( product varchar(32), country varchar(32), year int, profit int);
insert into sales  values ( 'Computer', 'India',2000, 1200),
( 'TV', 'United States', 1999, 150),
( 'Calculator', 'United States', 1999,50),
( 'Computer', 'United States', 1999,1500),
( 'Computer', 'United States', 2000,1500),
( 'TV', 'United States', 2000, 150),
( 'TV', 'India', 2000, 100),
( 'TV', 'India', 2000, 100),
( 'Calculator', 'United States', 2000,75),
( 'Calculator', 'India', 2000,75),
( 'TV', 'India', 1999, 100),
( 'Computer', 'India', 1999,1200),
( 'Computer', 'United States', 2000,1500),
( 'Calculator', 'United States', 2000,75);
select product, country , year, sum(profit) from sales group by product, country, year with cube;
explain select product, country , year, sum(profit) from sales group by product, country, year with cube;
select product, country , year, sum(profit) from sales group by product, country, year with rollup;
explain select product, country , year, sum(profit) from sales group by product, country, year with rollup;
select product, country , year, sum(profit) from sales group by product, country, year with cube union all select product, country , year, sum(profit) from sales group by product, country, year with rollup;
drop table sales;
+21 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ class Item {
  virtual bool get_date(TIME *ltime,bool fuzzydate);
  virtual bool get_time(TIME *ltime);
  virtual bool is_null() { return 0; }
  virtual unsigned int size_of () =0;
};


@@ -96,6 +97,7 @@ class Item_ident :public Item
    :db_name(db_name_par),table_name(table_name_par),field_name(field_name_par)
    { name = (char*) field_name_par; }
  const char *full_name() const;
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_field :public Item_ident
@@ -135,6 +137,7 @@ class Item_field :public Item_ident
  bool get_date(TIME *ltime,bool fuzzydate);  
  bool get_time(TIME *ltime);  
  bool is_null() { return field->is_null(); }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -156,6 +159,7 @@ class Item_null :public Item
  bool basic_const_item() const { return 1; }
  Item *new_item() { return new Item_null(name); }
  bool is_null() { return 1; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -185,6 +189,7 @@ class Item_int :public Item
  bool basic_const_item() const { return 1; }
  Item *new_item() { return new Item_int(name,value,max_length); }
  void print(String *str);
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -198,6 +203,7 @@ class Item_uint :public Item_int
  void make_field(Send_field *field);
  Item *new_item() { return new Item_uint(name,max_length); }
  void print(String *str);
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -228,6 +234,7 @@ class Item_real :public Item
  void make_field(Send_field *field);
  bool basic_const_item() const { return 1; }
  Item *new_item() { return new Item_real(name,value,decimals,max_length); }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -239,6 +246,7 @@ class Item_float :public Item_real
    decimals=NOT_FIXED_DEC;
    max_length=DBL_DIG+8;
  }
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_string :public Item
@@ -272,6 +280,7 @@ class Item_string :public Item
  String *const_string() { return &str_value; }
  inline void append(char *str,uint length) { str_value.append(str,length); }
  void print(String *str);
  virtual unsigned int size_of () { return sizeof(*this);}  
};

/* for show tables */
@@ -282,6 +291,7 @@ class Item_datetime :public Item_string
  Item_datetime(const char *item_name): Item_string(item_name,"",0)
  { max_length=19;}
  void make_field(Send_field *field);
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_empty_string :public Item_string
@@ -289,6 +299,7 @@ class Item_empty_string :public Item_string
public:
  Item_empty_string(const char *header,uint length) :Item_string("",0)
    { name=(char*) header; max_length=length;}
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_varbinary :public Item
@@ -303,6 +314,7 @@ class Item_varbinary :public Item
  bool save_in_field(Field *field);
  void make_field(Send_field *field);
  enum Item_result result_type () const { return INT_RESULT; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -315,6 +327,7 @@ class Item_result_field :public Item /* Item with result field */
  Field *tmp_table_field(TABLE *t_arg=(TABLE *)0) { return result_field; }
  table_map used_tables() const { return 1; }
  virtual void fix_length_and_dec()=0;
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -364,6 +377,7 @@ class Item_ref :public Item_ident
  void save_org_in_field(Field *field)	{ (*ref)->save_org_in_field(field); }
  enum Item_result result_type () const { return (*ref)->result_type(); }
  table_map used_tables() const		{ return (*ref)->used_tables(); }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -383,6 +397,7 @@ class Item_int_with_ref :public Item_int
  {
    return ref->save_in_field(field);
  }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -417,6 +432,7 @@ class Item_copy_string :public Item
  table_map used_tables() const { return (table_map) 1L; }
  bool const_item() const { return 0; }
  bool is_null() { return null_value; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -427,6 +443,7 @@ class Item_buff :public Sql_alloc
  Item_buff() :null_value(0) {}
  virtual bool cmp(void)=0;
  virtual ~Item_buff(); /*line -e1509 */
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_str_buff :public Item_buff
@@ -437,6 +454,7 @@ class Item_str_buff :public Item_buff
  Item_str_buff(Item *arg) :item(arg),value(arg->max_length) {}
  bool cmp(void);
  ~Item_str_buff();				// Deallocate String:s
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -447,6 +465,7 @@ class Item_real_buff :public Item_buff
public:
  Item_real_buff(Item *item_par) :item(item_par),value(0.0) {}
  bool cmp(void);
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_int_buff :public Item_buff
@@ -456,6 +475,7 @@ class Item_int_buff :public Item_buff
public:
  Item_int_buff(Item *item_par) :item(item_par),value(0) {}
  bool cmp(void);
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -472,6 +492,7 @@ class Item_field_buff :public Item_buff
    buff= (char*) sql_calloc(length=field->pack_length());
  }
  bool cmp(void);
  virtual unsigned int size_of () { return sizeof(*this);}  
};

extern Item_buff *new_Item_buff(Item *item);
+15 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ class Item_bool_func :public Item_int_func
  Item_bool_func(Item *a) :Item_int_func(a) {}
  Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
  void fix_length_and_dec() { decimals=0; max_length=1; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_bool_func2 :public Item_int_func
@@ -47,6 +48,7 @@ class Item_bool_func2 :public Item_int_func
  bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; }
  void print(String *str) { Item_func::print_op(str); }
  bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -80,6 +82,7 @@ class Item_func_equal :public Item_bool_func2
  enum Functype rev_functype() const { return EQUAL_FUNC; }
  cond_result eq_cmp_result() const { return COND_TRUE; }
  const char *func_name() const { return "<=>"; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -185,6 +188,7 @@ class Item_func_interval :public Item_int_func
  ~Item_func_interval() { delete item; }
  const char *func_name() const { return "interval"; }
  void update_used_tables();
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -199,6 +203,7 @@ class Item_func_ifnull :public Item_func
  enum Item_result result_type () const { return cached_result_type; }
  void fix_length_and_dec();
  const char *func_name() const { return "ifnull"; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -213,6 +218,7 @@ class Item_func_if :public Item_func
  enum Item_result result_type () const { return cached_result_type; }
  void fix_length_and_dec();
  const char *func_name() const { return "if"; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -227,6 +233,7 @@ class Item_func_nullif :public Item_bool_func2
  enum Item_result result_type () const { return cached_result_type; }
  void fix_length_and_dec();
  const char *func_name() const { return "nullif"; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -241,6 +248,7 @@ class Item_func_coalesce :public Item_func
  void fix_length_and_dec();
  enum Item_result result_type () const { return cached_result_type; }
  const char *func_name() const { return "coalesce"; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_func_case :public Item_func
@@ -261,6 +269,7 @@ class Item_func_case :public Item_func
  void print(String *str);
  bool fix_fields(THD *thd,struct st_table_list *tlist);
  Item *find_item(String *str);
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -422,6 +431,7 @@ class Item_func_in :public Item_int_func
  enum Functype functype() const { return IN_FUNC; }
  const char *func_name() const { return " IN "; }
  void update_used_tables();
  virtual unsigned int size_of () { return sizeof(*this);}  
};


@@ -459,6 +469,7 @@ class Item_func_isnull :public Item_bool_func
    }
  }
  optimize_type select_optimize() const { return OPTIMIZE_NULL; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_func_isnotnull :public Item_bool_func
@@ -473,6 +484,7 @@ class Item_func_isnotnull :public Item_bool_func
  }
  const char *func_name() const { return "isnotnull"; }
  optimize_type select_optimize() const { return OPTIMIZE_NULL; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};

class Item_func_like :public Item_bool_func2
@@ -506,6 +518,7 @@ class Item_func_like :public Item_bool_func2
  const char *func_name() const { return "like"; }
  void fix_length_and_dec();
  bool fix_fields(THD *thd,struct st_table_list *tlist);
  virtual unsigned int size_of () { return sizeof(*this);}  
};

#ifdef USE_REGEX
@@ -525,6 +538,7 @@ class Item_func_regex :public Item_bool_func
  longlong val_int();
  bool fix_fields(THD *thd,struct st_table_list *tlist);
  const char *func_name() const { return "regex"; }
  virtual unsigned int size_of () { return sizeof(*this);}  
};

#else
@@ -561,6 +575,7 @@ class Item_cond :public Item_bool_func
  void print(String *str);
  void split_sum_func(List<Item> &fields);
  friend int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds);
  virtual unsigned int size_of () { return sizeof(*this);}  
};


Loading