<commit_before>/*
   Copyright (c) 2011, 2012, <NAME> 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; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/*
  This file contains declarations for implementations
  of block based join algorithms
*/

#define JOIN_CACHE_INCREMENTAL_BIT           1
#define JOIN_CACHE_HASHED_BIT                2
#define JOIN_CACHE_BKA_BIT                   4

/* 
  Categories of data fields of variable length written into join cache buffers.
  The value of any of these fields is written into cache together with the
  prepended length of the value.     
*/
#define CACHE_BLOB      1        /* blob field  */
#define CACHE_STRIPPED  2        /* field stripped of trailing spaces */
#define CACHE_VARSTR1   3        /* short string value (length takes 1 byte) */ 
#define CACHE_VARSTR2   4        /* long string value (length takes 2 bytes) */
#define CACHE_ROWID     5        /* ROWID field */

/*
  The CACHE_FIELD structure used to describe fields of records that
  are written into a join cache buffer from record buffers and backward.
*/
typedef struct st_cache_field {
  uchar *str;   /**< buffer from/to where the field is to be copied */ 
  uint length;  /**< maximal number of bytes to be copied from/to str */
  /* 
    Field object for the moved field
    (0 - for a flag field, see JOIN_CACHE::create_flag_fields).
  */
  Field *field;
  uint type;    /**< category of the of the copied field (CACHE_BLOB et al.) */
  /* 
    The number of the record offset value for the field in the sequence
    of offsets placed after the last field of the record. These
    offset values are used to access fields referred to from other caches.
    If the value is 0 then no offset for the field is saved in the
    trailing sequence of offsets.
  */ 
  uint referenced_field_no; 
  /* The remaining structure fields are used as containers for temp values */
  uint blob_length; /**< length of the blob to be copied */
  uint offset;      /**< field offset to be saved in cache buffer */
} CACHE_FIELD;


class JOIN_TAB_SCAN;


/*
  JOIN_CACHE is the base class to support the implementations of 
  - Block Nested Loop (BNL) Join Algorithm,
  - Block Nested Loop Hash (BNLH) Join Algorithm,
  - Batched Key Access (BKA) Join Algorithm.
  The first algorithm is supported by the derived class JOIN_CACHE_BNL,
  the second algorithm is supported by the derived class JOIN_CACHE_BNLH,
  while the third algorithm is implemented in two variant supported by
  the classes JOIN_CACHE_BKA and JOIN_CACHE_BKAH.
  These three algorithms have a lot in common. Each of them first accumulates
  the records of the left join operand in a join buffer and then searches for
  matching rows of the second operand for all accumulated records.
  For the first two algorithms this strategy saves on logical I/O operations:
  the entire set of records from the join buffer requires only one look-through
  of the records provided by the second operand. 
  For the third algorithm the accumulation of records allows to optimize
  fetching rows of the second operand from disk for some engines (MyISAM, 
  InnoDB), or to minimize the number of round-trips between the Server and
  the engine nodes (NDB Cluster).        
*/ 

class JOIN_CACHE :public Sql_alloc
{

private:
<commit_msg>Better comments<commit_after>/*
   Copyright (c) 2011, 2012, Monty Program 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; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/*
  This file contains declarations for implementations
  of block based join algorithms
*/

#define JOIN_CACHE_INCREMENTAL_BIT           1
#define JOIN_CACHE_HASHED_BIT                2
#define JOIN_CACHE_BKA_BIT                   4

/* 
  Categories of data fields of variable length written into join cache buffers.
  The value of any of these fields is written into cache together with the
  prepended length of the value.     
*/
#define CACHE_BLOB      1        /* blob field  */
#define CACHE_STRIPPED  2        /* field stripped of trailing spaces */
#define CACHE_VARSTR1   3        /* short string value (length takes 1 byte) */ 
#define CACHE_VARSTR2   4        /* long string value (length takes 2 bytes) */
#define CACHE_ROWID     5        /* ROWID field */

/*
  The CACHE_FIELD structure used to describe fields of records that
  are written into a join cache buffer from record buffers and backward.
*/
typedef struct st_cache_field {
  uchar *str;   /**< buffer from/to where the field is to be copied */ 
  uint length;  /**< maximal number of bytes to be copied from/to str */
  /* 
    Field object for the moved field
    (0 - for a flag field, see JOIN_CACHE::create_flag_fields).
  */
  Field *field;
  uint type;    /**< category of the of the copied field (CACHE_BLOB et al.) */
  /* 
    The number of the record offset value for the field in the sequence
    of offsets placed after the last field of the record. These
    offset values are used to access fields referred to from other caches.
    If the value is 0 then no offset for the field is saved in the
    trailing sequence of offsets.
  */ 
  uint referenced_field_no; 
  /* The remaining structure fields are used as containers for temp values */
  uint blob_length; /**< length of the blob to be copied */
  uint offset;      /**< field offset to be saved in cache buffer */
} CACHE_FIELD;


class JOIN_TAB_SCAN;


/*
  JOIN_CACHE is the base class to support the implementations of 
  - Block Nested Loop (BNL) Join Algorithm,
  - Block Nested Loop Hash (BNLH) Join Algorithm,
  - Batched Key Access (BKA) Join Algorithm.

  The first algorithm is supported by the derived class JOIN_CACHE_BNL,
  the second algorithm is supported by the derived class JOIN_CACHE_BNLH,
  while the third algorithm is implemented in two variant supported by
  the classes JOIN_CACHE_BKA and JOIN_CACHE_BKAH.
  These three algorithms have a lot in common. Each of them first accumulates
  the records of the left join operand in a join buffer and then searches for
  matching rows of the second operand for all accumulated records.
  For the first two algorithms this strategy saves on logical I/O operations:
  the entire set of records from the join buffer requires only one look-through
  of the records provided by the second operand. 
  For the third algorithm the accumulation of records allows to optimize
  fetching rows of the second operand from disk for some engines (MyISAM, 
  InnoDB), or to minimize the number of round-trips between the Server and
  the engine nodes (NDB Cluster).        
*/ 

class JOIN_CACHE :public Sql_alloc
{

private:

{'fraction_non_alphanumeric': 0.04706490819756917, 'fraction_numerical': 0.009568140677527799, 'mean_word_length': 3.140792291220557, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841270', 'n_tokens_mistral': 2118, 'n_tokens_neox': 1977, 'n_words': 1094}