CUBRID Engine  latest
query_aggregate.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // query_aggregate - interface for executing aggregate function during queries
21 //
22 
23 #ifndef _QUERY_AGGREGATE_HPP_
24 #define _QUERY_AGGREGATE_HPP_
25 
26 #if !defined (SERVER_MODE) && !defined (SA_MODE)
27 #error Wrong module
28 #endif // not server and not SA mode
29 
30 #include "external_sort.h" // SORTKEY_INFO
31 #include "query_list.h"
32 #include "storage_common.h" // AGGREGATE_HASH_STATE, SCAN_CODE, FUNC_TYPE
33 
34 #include <vector>
35 
36 // forward definitions
37 struct db_value;
38 struct mht_table;
39 struct tp_domain;
40 struct val_descr;
41 
42 namespace cubxasl
43 {
44  struct aggregate_accumulator;
45  struct aggregate_accumulator_domain;
46  struct aggregate_list_node;
47 } // namespace cubxasl
48 
49 namespace cubquery
50 {
51  /* aggregate evaluation hash value */
53  {
54  int curr_size; /* last computed size of structure */
55  int tuple_count; /* # of tuples aggregated in structure */
56  int func_count; /* # of functions (i.e. accumulators) */
57  cubxasl::aggregate_accumulator *accumulators; /* function accumulators */
58  qfile_tuple_record first_tuple; /* first aggregated tuple */
59  };
60 
61  /* aggregate evaluation hash key */
63  {
64  int val_count; /* key size */
65  bool free_values; /* true if values need to be freed */
66  db_value **values; /* value array */
67  };
68 
69 
71  {
72  /* hash table stuff */
73  mht_table *hash_table; /* memory hash table for hash aggregate eval */
74  aggregate_hash_key *temp_key; /* temporary key used for fetch */
75  AGGREGATE_HASH_STATE state; /* state of hash aggregation */
76  tp_domain **key_domains; /* hash key domains */
77  cubxasl::aggregate_accumulator_domain **accumulator_domains; /* accumulator domains */
78 
79  /* runtime statistics stuff */
80  int hash_size; /* hash table size */
81  int group_count; /* groups processed in hash table */
82  int tuple_count; /* tuples processed in hash table */
83 
84  /* partial list file stuff */
85  SCAN_CODE part_scan_code; /* scan status of partial list file */
86  qfile_list_id *part_list_id; /* list with partial accumulators */
87  qfile_list_id *sorted_part_list_id; /* sorted list with partial acc's */
88  qfile_list_scan_id part_scan_id; /* scan on partial list */
89  db_value *temp_dbval_array; /* temporary array of dbvalues, used for saving entries to list files */
90 
91  /* partial list file sort stuff */
92  QFILE_TUPLE_RECORD input_tuple; /* tuple record used while sorting */
93  SORTKEY_INFO sort_key; /* sort key for partial list */
94  RECDES tuple_recdes; /* tuple recdes */
95  aggregate_hash_key *curr_part_key; /* current partial key */
96  aggregate_hash_key *temp_part_key; /* temporary partial key */
97  aggregate_hash_value *curr_part_value; /* current partial value */
98  aggregate_hash_value *temp_part_value; /* temporary partial value */
100  };
101 
102 
104  {
105  BTID *btids; /* hierarchy indexes */
106  HFID *hfids; /* HFIDs for classes in the hierarchy */
107  int count; /* number of classes in the hierarchy */
108  };
109 } // namespace cubquery
110 
111 // legacy aliases
116 
118  QUERY_ID query_id);
120  cubxasl::aggregate_accumulator_domain *acc_dom, FUNC_TYPE func_type,
121  tp_domain *func_domain, cubxasl::aggregate_accumulator *new_acc);
123  cubxasl::aggregate_accumulator *alt_acc_list);
125  OID *partition_cls_oid);
127  HFID *root_hfid, BTID *root_btid,
130  bool keep_list_file);
131 
132 cubquery::aggregate_hash_key *qdata_alloc_agg_hkey (cubthread::entry *thread_p, int val_cnt, bool alloc_vals);
137 int qdata_get_agg_hvalue_size (cubquery::aggregate_hash_value *value, bool ret_delta);
138 int qdata_free_agg_hentry (const void *key, void *data, void *args);
139 unsigned int qdata_hash_agg_hkey (const void *key, unsigned int ht_size);
141  cubquery::aggregate_hash_key *ckey2, int *diff_pos);
142 int qdata_agg_hkey_eq (const void *key1, const void *key2);
145  bool copy_vals);
147  cubquery::aggregate_hash_value *value, DB_VALUE *temp_dbval_array,
148  qfile_list_id *list_id);
150  cubquery::aggregate_hash_value *value, tp_domain **key_dom,
151  cubxasl::aggregate_accumulator_domain **acc_dom);
154  tp_domain **key_dom, cubxasl::aggregate_accumulator_domain **acc_dom);
156  qfile_list_id *partial_list_id, db_value *temp_dbval_array);
157 
158 #endif // _QUERY_AGGREGATE_HPP_
cubquery::aggregate_hash_key * qdata_alloc_agg_hkey(cubthread::entry *thread_p, int val_cnt, bool alloc_vals)
SCAN_CODE
int qdata_evaluate_aggregate_optimize(cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_ptr, HFID *hfid, OID *partition_cls_oid)
int qdata_evaluate_aggregate_list(cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_list, val_descr *vd, cubxasl::aggregate_accumulator *alt_acc_list)
int qdata_save_agg_hentry_to_list(cubthread::entry *thread_p, cubquery::aggregate_hash_key *key, cubquery::aggregate_hash_value *value, DB_VALUE *temp_dbval_array, qfile_list_id *list_id)
int qdata_load_agg_hentry_from_tuple(cubthread::entry *thread_p, QFILE_TUPLE tuple, cubquery::aggregate_hash_key *key, cubquery::aggregate_hash_value *value, tp_domain **key_dom, cubxasl::aggregate_accumulator_domain **acc_dom)
FUNC_TYPE
void qdata_free_agg_hvalue(cubthread::entry *thread_p, cubquery::aggregate_hash_value *value)
DB_VALUE_COMPARE_RESULT qdata_agg_hkey_compare(cubquery::aggregate_hash_key *ckey1, cubquery::aggregate_hash_key *ckey2, int *diff_pos)
aggregate_hash_value * temp_part_value
cubquery::aggregate_hash_value * qdata_alloc_agg_hvalue(cubthread::entry *thread_p, int func_cnt, cubxasl::aggregate_list_node *g_agg_list)
int qdata_evaluate_aggregate_hierarchy(cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_ptr, HFID *root_hfid, BTID *root_btid, cubquery::hierarchy_aggregate_helper *helper)
int qdata_get_agg_hkey_size(cubquery::aggregate_hash_key *key)
int qdata_agg_hkey_eq(const void *key1, const void *key2)
int qdata_free_agg_hentry(const void *key, void *data, void *args)
aggregate_hash_value * curr_part_value
AGGREGATE_HASH_STATE
SCAN_CODE qdata_load_agg_hentry_from_list(cubthread::entry *thread_p, qfile_list_scan_id *list_scan_id, cubquery::aggregate_hash_key *key, cubquery::aggregate_hash_value *value, tp_domain **key_dom, cubxasl::aggregate_accumulator_domain **acc_dom)
int qdata_aggregate_accumulator_to_accumulator(cubthread::entry *thread_p, cubxasl::aggregate_accumulator *acc, cubxasl::aggregate_accumulator_domain *acc_dom, FUNC_TYPE func_type, tp_domain *func_domain, cubxasl::aggregate_accumulator *new_acc)
aggregate_hash_key * curr_part_key
cubxasl::aggregate_accumulator * accumulators
unsigned int qdata_hash_agg_hkey(const void *key, unsigned int ht_size)
char * QFILE_TUPLE
Definition: query_list.h:281
aggregate_hash_key * temp_part_key
cubquery::aggregate_hash_key * qdata_copy_agg_hkey(cubthread::entry *thread_p, cubquery::aggregate_hash_key *key)
cubxasl::aggregate_accumulator_domain ** accumulator_domains
int qdata_finalize_aggregate_list(cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_list, bool keep_list_file)
void qdata_load_agg_hvalue_in_agg_list(cubquery::aggregate_hash_value *value, cubxasl::aggregate_list_node *agg_list, bool copy_vals)
int qdata_initialize_aggregate_list(cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_list, QUERY_ID query_id)
DB_VALUE_COMPARE_RESULT
Definition: dbtype_def.h:199
void qdata_free_agg_hkey(cubthread::entry *thread_p, cubquery::aggregate_hash_key *key)
int qdata_get_agg_hvalue_size(cubquery::aggregate_hash_value *value, bool ret_delta)
int qdata_save_agg_htable_to_list(cubthread::entry *thread_p, mht_table *hash_table, qfile_list_id *tuple_list_id, qfile_list_id *partial_list_id, db_value *temp_dbval_array)