[Maria-developers] Unsubscribe

2016-03-30 Thread Abdul Hakeem

___
Mailing list: https://launchpad.net/~maria-developers
Post to : maria-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Maria-developers] Please review MDEV-6353 my_ismbchar() and my_mbcharlen() refactoring

2016-03-30 Thread Sergei Golubchik
Hi, Alexander!

On Mar 30, Alexander Barkov wrote:
> commit 4ab28aca964fa646aa55676db813dbed66b83093
> Author: Alexander Barkov 
> Date:   Mon Mar 28 11:05:51 2016 +0400
> 
> MDEV-6353 my_ismbchar() and my_mbcharlen() refactoring, part 1.
> Fixing the debug_sync and create_options related code not to use 
> my_mbcharlen():
> - debug_sync_token() now uses cs->cset->scan().
>   Passing the end of the string pointer to debug_sync_update() in order 
> to be
>   able to use scan(). Adding support for a new pattern 
> scan(MY_SEQ_NONSPACES).
>   It does scans everything that scan(MY_SEQ_SPACES) does not.
> - Fixing set_one_value() to iterate bytes one by one. This is safe, 
> because
>   ',' cannot be a part of a multi-byte character in UTF8.

Looks ok, thanks!
But don't push this commit alone, please.
Wait until all parts of MDEV-6353 are ready and push them together.

Regards,
Sergei
Chief Architect MariaDB
and secur...@mariadb.org

___
Mailing list: https://launchpad.net/~maria-developers
Post to : maria-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Maria-developers] MDEV-7773, Aggregate Stored Functions

2016-03-30 Thread Soham Mankad
Thank you Oleksandr Byelkin sir for letting me know that I was working in
wrong direction and yes I will pay more attention towards what is written
in knowledge base and comments of MDEV-7773

Regards,
Soham Mankad
___
Mailing list: https://launchpad.net/~maria-developers
Post to : maria-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp


[Maria-developers] Please review MDEV-6353 my_ismbchar() and my_mbcharlen() refactoring

2016-03-30 Thread Alexander Barkov
Hi Sergei,

Please review a partial patch for MDEV-6353.

It removes my_mbcharlen() in all remaining pieces of the code,
except LOAD DATA and SELECT INTO OUTFILE.


I'll do LOAD DATA and SELECT INTO OUTFILE in a separate patch.


Thanks.

commit 4ab28aca964fa646aa55676db813dbed66b83093
Author: Alexander Barkov 
Date:   Mon Mar 28 11:05:51 2016 +0400

MDEV-6353 my_ismbchar() and my_mbcharlen() refactoring, part 1.
Fixing the debug_sync and create_options related code not to use my_mbcharlen():
- debug_sync_token() now uses cs->cset->scan().
  Passing the end of the string pointer to debug_sync_update() in order to be
  able to use scan(). Adding support for a new pattern scan(MY_SEQ_NONSPACES).
  It does scans everything that scan(MY_SEQ_SPACES) does not.
- Fixing set_one_value() to iterate bytes one by one. This is safe, because
  ',' cannot be a part of a multi-byte character in UTF8.

diff --git a/include/m_ctype.h b/include/m_ctype.h
index 615ee6a..a2605dd 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -182,6 +182,7 @@ extern MY_UNI_CTYPE my_uni_ctype[256];
 
 #define MY_SEQ_INTTAIL	1
 #define MY_SEQ_SPACES	2
+#define MY_SEQ_NONSPACES 3 /* Skip non-space characters, including bad bytes */
 
 /* My charsets_list flags */
 #define MY_CS_COMPILED  1  /* compiled-in sets   */
diff --git a/sql/create_options.cc b/sql/create_options.cc
index 66515be..3011c4b 100644
--- a/sql/create_options.cc
+++ b/sql/create_options.cc
@@ -184,7 +184,7 @@ static bool set_one_value(ha_create_table_option *opt,
   {
 for (end=start;
  *end && *end != ',';
- end+= my_mbcharlen(system_charset_info, *end)) /* no-op */;
+ end++) /* no-op */;
 if (!my_strnncoll(system_charset_info,
   (uchar*)start, end-start,
   (uchar*)value->str, value->length))
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index 8b3412e..e84f1e8 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -847,16 +847,16 @@ static bool debug_sync_set_action(THD *thd, st_debug_sync_action *action)
 to the string terminator ASCII NUL ('\0').
 */
 
-static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr)
+static char *debug_sync_token(char **token_p, uint *token_length_p,
+  char *ptr, char *ptrend)
 {
   DBUG_ASSERT(token_p);
   DBUG_ASSERT(token_length_p);
   DBUG_ASSERT(ptr);
 
   /* Skip leading space */
-  while (my_isspace(system_charset_info, *ptr))
-ptr+= my_mbcharlen(system_charset_info, (uchar) *ptr);
-
+  ptr+= system_charset_info->cset->scan(system_charset_info,
+ptr, ptrend, MY_SEQ_SPACES);
   if (!*ptr)
   {
 ptr= NULL;
@@ -867,8 +867,8 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr)
   *token_p= ptr;
 
   /* Find token end. */
-  while (*ptr && !my_isspace(system_charset_info, *ptr))
-ptr+= my_mbcharlen(system_charset_info, (uchar) *ptr);
+  ptr+= system_charset_info->cset->scan(system_charset_info,
+ptr, ptrend, MY_SEQ_NONSPACES);
 
   /* Get token length. */
   *token_length_p= ptr - *token_p;
@@ -876,18 +876,19 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr)
   /* If necessary, terminate token. */
   if (*ptr)
   {
+DBUG_ASSERT(ptr < ptrend);
 /* Get terminator character length. */
-uint mbspacelen= my_mbcharlen(system_charset_info, (uchar) *ptr);
+int mbspacelen= my_charlen(system_charset_info, ptr, ptrend);
 
 /* Terminate token. */
 *ptr= '\0';
 
 /* Skip the terminator. */
-ptr+= mbspacelen;
+ptr+= mbspacelen < 1 ? 1 : mbspacelen;
 
 /* Skip trailing space */
-while (my_isspace(system_charset_info, *ptr))
-  ptr+= my_mbcharlen(system_charset_info, (uchar) *ptr);
+ptr+= system_charset_info->cset->scan(system_charset_info,
+  ptr, ptrend, MY_SEQ_SPACES);
   }
 
  end:
@@ -917,7 +918,8 @@ static char *debug_sync_token(char **token_p, uint *token_length_p, char *ptr)
 undefined in this case.
 */
 
-static char *debug_sync_number(ulong *number_p, char *actstrptr)
+static char *debug_sync_number(ulong *number_p, char *actstrptr,
+char *actstrend)
 {
   char  *ptr;
   char  *ept;
@@ -927,7 +929,7 @@ static char *debug_sync_number(ulong *number_p, char *actstrptr)
   DBUG_ASSERT(actstrptr);
 
   /* Get token from string. */
-  if (!(ptr= debug_sync_token(, _length, actstrptr)))
+  if (!(ptr= debug_sync_token(, _length, actstrptr, actstrend)))
 goto end;
 
   *number_p= strtoul(token, , 10);
@@ -971,7 +973,7 @@ static char *debug_sync_number(ulong *number_p, char *actstrptr)
 for the string.
 */
 
-static bool debug_sync_eval_action(THD *thd, char *action_str)
+static 

Re: [Maria-developers] MDEV-8360 Clean-up CHARSET_INFO: strnncollsp: diff_if_only_endspace_difference

2016-03-30 Thread Sergei Golubchik
Hi, Alexander!

On Mar 25, Alexander Barkov wrote:
> Hi Sergei,
> 
> please review a patch for MDEV-8360.

Looks good!
Ok to push.

> Btw, shouldn't we remove:
> 
> #define HA_END_SPACE_ARE_EQUAL   512
> 
> in ./include/my_base.h ?
> 
> It's not really needed.

Yes, please do.

> commit 75ae61719e43dd0924b3a0cc5c9b588b82daeec8
> Author: Alexander Barkov 
> Date:   Fri Mar 25 13:50:41 2016 +0400
> 
> MDEV-8360 Clean-up CHARSET_INFO: strnncollsp: 
> diff_if_only_endspace_difference
> 
> - Removing the "diff_if_only_endspace_difference" argument from
>   MY_COLLATION_HANDLER::strnncollsp(), my_strnncollsp_simple(),
>   as well as in the function template MY_FUNCTION_NAME(strnncollsp)
>   in strcoll.ic
> 
> - Removing the "diff_if_only_space_different" from ha_compare_text(),
>   hp_rec_key_cmp().
> 
> - Adding a new function my_strnncollsp_padspace_bin() and reusing
>   it instead of duplicate code pieces in my_strnncollsp_8bit_bin(),
>   my_strnncollsp_latin1_de(), my_strnncollsp_tis620(),
>   my_strnncollsp_utf8_cs().
> 
> - Adding more tests for better coverage of the trailing space handling.
> 
> diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c
> index 1027255..8331de3 100644
> --- a/strings/ctype-bin.c
> +++ b/strings/ctype-bin.c
> @@ -182,31 +192,10 @@ static int my_strnncollsp_8bit_bin(CHARSET_INFO * cs 
> __attribute__((unused)),
>  if (*a++ != *b++)
>return ((int) a[-1] - (int) b[-1]);
>}
> -  res= 0;
> -  if (a_length != b_length)
> -  {
> -int swap= 1;
> -/*
> -  Check the next not space character of the longer key. If it's < ' ',
> -  then it's smaller than the other key.
> -*/
> -if (diff_if_only_endspace_difference)
> -  res= 1;   /* Assume 'a' is bigger */
> -if (a_length < b_length)
> -{
> -  /* put shorter key in s */
> -  a_length= b_length;
> -  a= b;
> -  swap= -1;  /* swap sign of result 
> */
> -  res= -res;
> -}
> -for (end= a + a_length-length; a < end ; a++)
> -{
> -  if (*a != ' ')
> - return (*a < ' ') ? -swap : swap;
> -}
> -  }
> -  return res;
> +  return a_length == b_length ? 0 :
> + a_length < b_length  ?
> +   -my_strnncollsp_padspace_bin(b, b_length - length) :
> +   my_strnncollsp_padspace_bin(a, a_length - length);

That's much easier to understand. Thanks!

Regards,
Sergei
Chief Architect MariaDB
and secur...@mariadb.org

___
Mailing list: https://launchpad.net/~maria-developers
Post to : maria-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Maria-developers] MDEV-7773, Aggregate Stored Functions

2016-03-30 Thread Oleksandr Byelkin

Hi, Soham!

On 30.03.2016 16:28, Soham Mankad wrote:
[skip]


Please let me know whether I am working in right direction or not and 
whether the methods I have mentioned can be used or not to implement 
the project.




Sorry, but you e-mail makes me think that you have not read comments to 
the MDEV-7773. Please do, Sergei made clear descriptions of possible 
ways to make this.


___
Mailing list: https://launchpad.net/~maria-developers
Post to : maria-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Maria-developers] MDEV-7773, Aggregate Stored Functions

2016-03-30 Thread Soham Mankad
Respected Sir,

I have found some of ways to implement this project using C++, SQL, java,
or C.

As I had mentioned earlier, I was searching for some of database systems
that have this facility or in some way can implement it.

The database system that I discovered while learning for this topic is HP
Vertica and in this system the basic approach is creating
user defined library saved as .so for C/C++ or .jarr for java and loading
it using CREATE LIBRARY command. When we call SQL function HP Vertica passes
data values to the code in the library to process it.

Syntax:
CREATE [ OR REPLACE ] AGGREGATE FUNCTION [[db-name.]schema.]function-name
... AS LANGUAGE 'language' NAME 'factory' LIBRARY library_name;

example using this method is as given below


 => CREATE LIBRARY AggregateFunctions AS
'/opt/vertica/sdk/examples/build/AggregateFunctions.so';

CREATE LIBRARY
=> CREATE AGGREGATE FUNCTION ag_avg AS LANGUAGE 'C++' NAME 'AverageFactory'
   library AggregateFunctions;
CREATE AGGREGATE FUNCTION
=> CREATE AGGREGATE FUNCTION ag_cat AS LANGUAGE 'C++' NAME 'ConcatenateFactory'
   library AggregateFunctions;
CREATE AGGREGATE FUNCTION
=> \x
Expanded display is on.
select * from user_functions;

The only drawback in this method that this can be implemented using C++
only for HP Vertica.

The another method that I discovered is given in the latest update of
oracle i.e Oracle 9i (9)
the refrence link for same is
http://www.oracle-developer.net/display.php?id=215

According to this we require two components to implement aggregate functions

1. an object type specification and body; and

2. a PL/SQL function.

There is a development framework for data cartridges (think of this as a
template) provided by Oracle. This provides the structure of the object
type and its methods (down to the detail of how we name them) and also
defines how we create our PL/SQL function. For example, our object type
will contain the following:attribute(s) for holding state information.
These can be of any existing built-in or user-defined datatype;

   - a mandatory ODCIAggregateInitialize static method to reset the state
   attributes at the start of an aggregation;
   - a mandatory ODCIAggregateIterate member method to apply each input
   value to the running aggregate value;
   - a mandatory ODCIAggregateTerminate member method to return the final
   result of the aggregate; and
   - an optional ODCIAggregateMerge member method, used to combine the
   results of more than one stream of aggregation (for example, with parallel
   query) before returning a result.

More detailed information, explanation and examples are given in the link
that I have mentioned above.

Please let me know whether I am working in right direction or not and
whether the methods I have mentioned can be used or not to implement the
project.

Regards,
Soham Mankad
___
Mailing list: https://launchpad.net/~maria-developers
Post to : maria-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Maria-developers] 1e883e9: MDEV-5535: Cannot reopen temporary table

2016-03-30 Thread Sergei Golubchik
Hi, Nirbhay!

Here's a review of MDEV-5535.
Sorry, it took a while - this was a big patch.

The approach is fine, my comments are mostly about details.

On Mar 07, Nirbhay Choubey wrote:

> diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result
> index ee0b3ab..94b02a6 100644
> --- a/mysql-test/r/temp_table.result
> +++ b/mysql-test/r/temp_table.result
> @@ -308,3 +308,185 @@ show status like 'com_drop%table';
>  Variable_nameValue
>  Com_drop_table   2
>  Com_drop_temporary_table 1
> +#
> +# MDEV-5535: Cannot reopen temporary table
> +#
> +DROP DATABASE IF EXISTS temp_db;
> +CREATE DATABASE temp_db;
> +USE temp_db;
> +#
> +# SHOW TABLES do not list temporary tables.
> +#
> +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
> +INSERT INTO temp_t1 VALUES(1);
> +SELECT * FROM temp_t1;
> +i
> +1
> +SHOW TABLES;
> +Tables_in_temp_db
> +DROP TABLE temp_t1;
> +#
> +# Create and drop a temporary table.
> +#
> +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
> +INSERT INTO temp_t1 VALUES(1);
> +SELECT * FROM temp_t1;
> +i
> +1
> +DROP TABLE temp_t1;
> +SELECT * FROM temp_t1;
> +ERROR 42S02: Table 'temp_db.temp_t1' doesn't exist
> +#
> +# Create a tempporary table and base table with same name and DROP TABLE.
> +#
> +CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
> +INSERT INTO t1 VALUES("BASE TABLE");
> +CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
> +INSERT INTO t1 VALUES("TEMPORARY TABLE");
> +SELECT * FROM t1;
> +c1
> +TEMPORARY TABLE
> +DROP TABLE t1;
> +SELECT * FROM t1;
> +c1
> +BASE TABLE
> +DROP TABLE t1;
> +SELECT * FROM t1;
> +ERROR 42S02: Table 'temp_db.t1' doesn't exist
> +#
> +# Create a tempporary table and base table with same name and DROP TEMPORARY
> +# TABLE.
> +#
> +CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
> +INSERT INTO t1 VALUES("BASE TABLE");
> +CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
> +INSERT INTO t1 VALUES("TEMPORARY TABLE");
> +SELECT * FROM t1;
> +c1
> +TEMPORARY TABLE
> +DROP TEMPORARY TABLE t1;
> +SELECT * FROM t1;
> +c1
> +BASE TABLE
> +DROP TEMPORARY TABLE t1;
> +ERROR 42S02: Unknown table 'temp_db.t1'
> +SELECT * FROM t1;
> +c1
> +BASE TABLE
> +DROP TABLE t1;
> +#
> +# Create a temporary table and drop its parent database.
> +#
> +USE temp_db;
> +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
> +INSERT INTO temp_t1 VALUES (1);
> +DROP DATABASE temp_db;
> +CREATE DATABASE temp_db;
> +USE temp_db;
> +DROP TEMPORARY TABLE temp_t1;
> +#
> +# Similar to above, but this time with a base table with same name.
> +#
> +USE temp_db;
> +CREATE TABLE t1(i INT)ENGINE=INNODB;
> +CREATE TEMPORARY TABLE t1(i INT) ENGINE=INNODB;
> +INSERT INTO t1 VALUES (1);
> +DROP DATABASE temp_db;
> +CREATE DATABASE temp_db;
> +USE temp_db;
> +DROP TEMPORARY TABLE t1;
> +DROP TABLE t1;
> +ERROR 42S02: Unknown table 'temp_db.t1'
> +#
> +# Create a temporary table within a function.
> +#
> +USE temp_db;
> +CREATE FUNCTION f1() RETURNS INT
> +BEGIN
> +DROP TEMPORARY TABLE IF EXISTS temp_t1;
> +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
> +INSERT INTO `temp_t1` VALUES(1);
> +RETURN (SELECT COUNT(*) FROM temp_t1);
> +END|
> +SELECT f1();
> +f1()
> +1
> +SELECT * FROM temp_t1;
> +i
> +1
> +DROP TABLE temp_t1;
> +CREATE TEMPORARY TABLE `temp_t1`(i INT) ENGINE=INNODB;
> +SELECT f1();
> +f1()
> +1
> +SELECT * FROM temp_t1;
> +i
> +1
> +DROP FUNCTION f1;
> +#
> +# Create and drop a temporary table within a function.
> +#
> +CREATE FUNCTION f2() RETURNS INT
> +BEGIN
> +DROP TEMPORARY TABLE IF EXISTS temp_t1;
> +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
> +INSERT INTO temp_t1 VALUES(1);
> +DROP TABLE temp_t1;
> +RETURN 0;
> +END|
> +ERROR HY000: Explicit or implicit commit is not allowed in stored function 
> or trigger.
> +#
> +# Create a temporary table within a function and select it from another
> +# function.
> +#
> +CREATE FUNCTION f2() RETURNS INT
> +BEGIN
> +DROP TEMPORARY TABLE IF EXISTS temp_t1;
> +CREATE TEMPORARY TABLE temp_t1 (i INT) ENGINE=INNODB;
> +INSERT INTO temp_t1 VALUES (1);
> +RETURN f2_1();
> +END|
> +CREATE FUNCTION f2_1() RETURNS INT
> +RETURN (SELECT COUNT(*) FROM temp_t1)|
> +DROP TEMPORARY TABLE temp_t1;
> +SELECT f2();
> +f2()
> +1
> +DROP TEMPORARY TABLE temp_t1;
> +DROP FUNCTION f2;
> +#
> +# Create temporary table like base table.
> +#
> +CREATE TABLE t1(i INT) ENGINE=INNODB;
> +INSERT INTO t1 VALUES(1);
> +CREATE TEMPORARY TABLE temp_t1 LIKE t1;
> +SELECT * FROM temp_t1;
> +i
> +CREATE TEMPORARY TABLE t1 LIKE t1;
> +ERROR 42000: Not unique table/alias: 't1'
> +DROP TABLE temp_t1, t1;
> +#
> +# Create temporary table as base table.
> +#
> +CREATE TABLE t1(i INT) ENGINE=INNODB;
> +INSERT INTO t1 VALUES(1);
> +CREATE TEMPORARY TABLE temp_t1 AS SELECT * FROM t1;
> +SELECT * FROM temp_t1;
> +i
> +1
> +DROP TABLE temp_t1, t1;
> +#
> +# Reopen temporary table
> +#
> +CREATE TEMPORARY TABLE temp_t1(i int)ENGINE=INNODB;
> +INSERT INTO temp_t1 VALUES(1), (2);
> +SELECT * FROM temp_t1 a, temp_t1 

Re: [Maria-developers] [Commits] d40d68f: Convert percent_rank to work with cursors

2016-03-30 Thread Sergey Petrunia
On Mon, Mar 28, 2016 at 10:58:55PM +0300, Vicentiu Ciorbaru wrote:
> revision-id: d40d68f23602be9886c1b502fdad9d23bdc9a0fb 
> (mariadb-10.1.8-187-gd40d68f)
> parent(s): bf18dac08fe0ae18975158e786fee097883949d4
> author: Vicențiu Ciorbaru
> committer: Vicențiu Ciorbaru
> timestamp: 2016-03-28 22:51:42 +0300
> message:
> 
> Convert percent_rank to work with cursors
> 
> The percent_rank function now is compatible with the cursor algorithm.
> We no longer need a special implementation for it to work.
> 
> ---
>  sql/item_windowfunc.h |  77 +++
>  sql/sql_window.cc | 165 
> +-
>  2 files changed, 91 insertions(+), 151 deletions(-)
> 
> diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
> index 6f91bc8..1dd483c 100644
> --- a/sql/item_windowfunc.h
> +++ b/sql/item_windowfunc.h
> @@ -317,12 +317,18 @@ class Item_context
>NOTE: All two pass window functions need to implement
>this interface.
>  */
> -class Item_sum_window_with_context : public Item_sum_num,
> - public Item_context
> +class Item_sum_window_with_row_count : public Item_sum_num
>  {
>   public:
> -  Item_sum_window_with_context(THD *thd)
> -   : Item_sum_num(thd), Item_context() {}
> +  Item_sum_window_with_row_count(THD *thd) : Item_sum_num(thd),
> + partition_row_count_(0){}
> +
> +  void set_row_count(ulonglong count) { partition_row_count_ = count; }
> +
> + protected:
> +  longlong get_row_count() { return partition_row_count_; }
> + private:
> +  ulonglong partition_row_count_;
>  };
>  
>  /*
> @@ -336,12 +342,11 @@ class Item_sum_window_with_context : public 
> Item_sum_num,
>  This is held within the row_count context.
>- Second pass to compute rank of current row and the value of the function
>  */
> -class Item_sum_percent_rank: public Item_sum_window_with_context,
> - public Window_context_row_count
> +class Item_sum_percent_rank: public Item_sum_window_with_row_count
>  {
>   public:
>Item_sum_percent_rank(THD *thd)
> -: Item_sum_window_with_context(thd), cur_rank(1) {}
> +: Item_sum_window_with_row_count(thd), cur_rank(1) {}
>  
>longlong val_int()
>{
> @@ -359,14 +364,9 @@ class Item_sum_percent_rank: public 
> Item_sum_window_with_context,
>   We can not get the real value without knowing the number of rows
>   in the partition. Don't divide by 0.
> */
> -   if (!get_context_())
> -   {
> - // Calling this kind of function with a context makes no sense.
> - DBUG_ASSERT(0);
> - return 0;
> -   }
> -
> -   longlong partition_rows = get_context_()->get_field_context(result_field);
> +   ulonglong partition_rows = get_row_count();
> +   null_value= partition_rows > 0 ? false : true;
> +
> return partition_rows > 1 ?
>   static_cast(cur_rank - 1) / (partition_rows - 1) : 0;
>}
> @@ -381,25 +381,6 @@ class Item_sum_percent_rank: public 
> Item_sum_window_with_context,
>  return "percent_rank";
>}
>  
> -  bool create_window_context()
> -  {
> -// TODO-cvicentiu: Currently this means we must make sure to delete
> -// the window context. We can potentially allocate this on the THD 
> memroot.
> -// At the same time, this is only necessary for a small portion of the
> -// query execution and it does not make sense to keep it for all of it.
> -context_ = new Window_context_row_count();
> -if (context_ == NULL)
> -  return true;
> -return false;
> -  }
> -
> -  void delete_window_context()
> -  {
> -if (context_)
> -  delete get_context_();
> -context_ = NULL;
> -  }
> -
>void update_field() {}
>  
>void clear()
> @@ -428,13 +409,6 @@ class Item_sum_percent_rank: public 
> Item_sum_window_with_context,
>void cleanup()
>{
>  peer_tracker.cleanup();
> -Item_sum_window_with_context::cleanup();
> -  }
> -
> -  /* Helper function so that we don't cast the context every time. */
> -  Window_context_row_count* get_context_()
> -  {
> -return static_cast(context_);
>}
>  };
>  
> @@ -517,6 +491,27 @@ class Item_window_func : public Item_func_or_sum
>  }
>}
>  
> +  bool requires_partition_size() const
> +  {
> +switch (window_func()->sum_func()) {
> +case Item_sum::PERCENT_RANK_FUNC:
> +case Item_sum::CUME_DIST_FUNC:
> +  return true;
> +default:
> +  return false;
> +}
> +  }
> +
> +  bool requires_peer_size() const
> +  {
> +switch (window_func()->sum_func()) {
> +case Item_sum::CUME_DIST_FUNC:
> +  return true;
> +default:
> +  return false;
> +}
> +  }
This function seem not to be used anywhere?

> +
>bool is_order_list_mandatory() const
>{
>  switch (window_func()->sum_func()) {
> diff --git a/sql/sql_window.cc b/sql/sql_window.cc
> index e8e226b..1bfac7a 100644
> --- a/sql/sql_window.cc
> +++ b/sql/sql_window.cc
> @@ -865,15