CUBRID Engine  latest
query_aggregate.cpp File Reference
#include "query_aggregate.hpp"
#include "arithmetic.h"
#include "btree.h"
#include "db_json.hpp"
#include "dbtype.h"
#include "fetch.h"
#include "list_file.h"
#include "memory_alloc.h"
#include "memory_hash.h"
#include "object_domain.h"
#include "object_primitive.h"
#include "object_representation.h"
#include "query_opfunc.h"
#include "regu_var.hpp"
#include "string_opfunc.h"
#include "xasl.h"
#include "xasl_aggregate.hpp"
#include <cmath>
Include dependency graph for query_aggregate.cpp:

Go to the source code of this file.

Functions

static int qdata_aggregate_value_to_accumulator (cubthread::entry *thread_p, cubxasl::aggregate_accumulator *acc, cubxasl::aggregate_accumulator_domain *domain, FUNC_TYPE func_type, tp_domain *func_domain, db_value *value, bool is_acc_to_acc)
 
static int qdata_aggregate_multiple_values_to_accumulator (cubthread::entry *thread_p, cubxasl::aggregate_accumulator *acc, cubxasl::aggregate_accumulator_domain *domain, FUNC_TYPE func_type, tp_domain *func_domain, std::vector< DB_VALUE > &db_values)
 
static int qdata_process_distinct_or_sort (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_p, QUERY_ID query_id)
 
static int qdata_calculate_aggregate_cume_dist_percent_rank (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_p, VAL_DESCR *val_desc_p)
 
static int qdata_update_agg_interpolation_func_value_and_domain (cubxasl::aggregate_list_node *agg_p, DB_VALUE *val)
 
static int qdata_aggregate_interpolation (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_p, QFILE_LIST_SCAN_ID *scan_id)
 
static int qdata_group_concat_first_value (THREAD_ENTRY *thread_p, AGGREGATE_TYPE *agg_p, DB_VALUE *dbvalue)
 
static int qdata_group_concat_value (THREAD_ENTRY *thread_p, AGGREGATE_TYPE *agg_p, DB_VALUE *dbvalue)
 
int qdata_initialize_aggregate_list (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_list_p, QUERY_ID query_id)
 
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)
 
int qdata_evaluate_aggregate_list (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_list_p, val_descr *val_desc_p, cubxasl::aggregate_accumulator *alt_acc_list)
 
int qdata_evaluate_aggregate_optimize (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_p, HFID *hfid_p, OID *super_oid)
 
int qdata_evaluate_aggregate_hierarchy (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_p, HFID *root_hfid, BTID *root_btid, hierarchy_aggregate_helper *helper)
 
int qdata_finalize_aggregate_list (cubthread::entry *thread_p, cubxasl::aggregate_list_node *agg_list_p, bool keep_list_file)
 
aggregate_hash_keyqdata_alloc_agg_hkey (cubthread::entry *thread_p, int val_cnt, bool alloc_vals)
 
void qdata_free_agg_hkey (cubthread::entry *thread_p, aggregate_hash_key *key)
 
aggregate_hash_valueqdata_alloc_agg_hvalue (cubthread::entry *thread_p, int func_cnt, cubxasl::aggregate_list_node *g_agg_list)
 
void qdata_free_agg_hvalue (cubthread::entry *thread_p, aggregate_hash_value *value)
 
int qdata_get_agg_hkey_size (aggregate_hash_key *key)
 
int qdata_get_agg_hvalue_size (aggregate_hash_value *value, bool ret_delta)
 
int qdata_free_agg_hentry (const void *key, void *data, void *args)
 
unsigned int qdata_hash_agg_hkey (const void *key, unsigned int ht_size)
 
DB_VALUE_COMPARE_RESULT qdata_agg_hkey_compare (aggregate_hash_key *ckey1, aggregate_hash_key *ckey2, int *diff_pos)
 
int qdata_agg_hkey_eq (const void *key1, const void *key2)
 
aggregate_hash_keyqdata_copy_agg_hkey (cubthread::entry *thread_p, aggregate_hash_key *key)
 
void qdata_load_agg_hvalue_in_agg_list (aggregate_hash_value *value, cubxasl::aggregate_list_node *agg_list, bool copy_vals)
 
int qdata_save_agg_hentry_to_list (cubthread::entry *thread_p, aggregate_hash_key *key, 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, aggregate_hash_key *key, aggregate_hash_value *value, tp_domain **key_dom, cubxasl::aggregate_accumulator_domain **acc_dom)
 
SCAN_CODE qdata_load_agg_hentry_from_list (cubthread::entry *thread_p, qfile_list_scan_id *list_scan_id, aggregate_hash_key *key, aggregate_hash_value *value, tp_domain **key_dom, cubxasl::aggregate_accumulator_domain **acc_dom)
 
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)
 

Function Documentation

DB_VALUE_COMPARE_RESULT qdata_agg_hkey_compare ( aggregate_hash_key ckey1,
aggregate_hash_key ckey2,
int *  diff_pos 
)

Definition at line 2212 of file query_aggregate.cpp.

References assert, DB_EQ, DB_UNK, i, tp_value_compare(), cubquery::aggregate_hash_key::val_count, and cubquery::aggregate_hash_key::values.

Referenced by qdata_agg_hkey_eq(), and qexec_locate_agg_hentry_in_list().

Here is the caller graph for this function:

int qdata_agg_hkey_eq ( const void *  key1,
const void *  key2 
)

Definition at line 2254 of file query_aggregate.cpp.

References DB_EQ, and qdata_agg_hkey_compare().

Referenced by qexec_alloc_agg_hash_context(), and qexec_hash_gby_put_next().

Here is the caller graph for this function:

static int qdata_aggregate_multiple_values_to_accumulator ( cubthread::entry thread_p,
cubxasl::aggregate_accumulator acc,
cubxasl::aggregate_accumulator_domain *  domain,
FUNC_TYPE  func_type,
tp_domain func_domain,
std::vector< DB_VALUE > &  db_values 
)
static
int qdata_evaluate_aggregate_list ( cubthread::entry thread_p,
cubxasl::aggregate_list_node agg_list_p,
val_descr val_desc_p,
cubxasl::aggregate_accumulator alt_acc_list 
)

Definition at line 594 of file query_aggregate.cpp.

References cubxasl::aggregate_list_node::accumulator, ARG_FILE_LINE, assert, cubxasl::aggregate_percentile_info::cur_group_percentile, cubxasl::aggregate_accumulator::curr_cnt, pr_type::data_writeval(), db_get_double(), DB_IS_NULL, db_json_allocate_doc(), db_make_json(), db_private_alloc, db_private_free_and_init, DB_TYPE_BIGINT, DB_TYPE_DATE, DB_TYPE_DATETIME, DB_TYPE_DATETIMELTZ, DB_TYPE_DATETIMETZ, DB_TYPE_DOUBLE, DB_TYPE_FLOAT, DB_TYPE_INTEGER, DB_TYPE_MONETARY, DB_TYPE_NUMERIC, DB_TYPE_SHORT, DB_TYPE_TIME, DB_TYPE_TIMESTAMP, DB_TYPE_TIMESTAMPLTZ, DB_TYPE_TIMESTAMPTZ, DB_VALUE_DOMAIN_TYPE, DB_VALUE_TYPE, db_values, cubxasl::aggregate_list_node::domain, DOMAIN_COMPATIBLE, ER_ARG_CAN_NOT_BE_CASTED_TO_DESIRED_DOMAIN, er_errid(), ER_ERROR_SEVERITY, ER_FAILED, ER_JSON_OBJECT_NAME_IS_NULL, ER_PERCENTILE_FUNC_INVALID_PERCENTILE_RANGE, ER_PERCENTILE_FUNC_PERCENTILE_CHANGED_IN_GROUP, ER_QPROC_INVALID_DATATYPE, er_set(), ER_TF_BUFFER_OVERFLOW, error(), fcode_get_uppercase_name(), fetch_copy_dbval(), fetch_peek_dbval(), cubxasl::aggregate_list_node::flag_agg_optimize, cubxasl::aggregate_list_node::function, i, cubxasl::aggregate_list_node::info, cubxasl::aggregate_list_node::list_id, cubxasl::aggregate_list_node::next, regu_variable_list_node::next, NO_ERROR, NULL, cubxasl::aggregate_list_node::operands, cubxasl::aggregate_list_node::opr_dbtype, cubxasl::aggregate_list_node::option, OR_BUF_INIT, cubxasl::aggregate_specific_function_info::percentile, cubxasl::aggregate_percentile_info::percentile_reguvar, pr_clear_value(), pr_clear_value_vector(), pr_clone_value(), pr_data_writeval_disk_size(), pr_type_from_id(), PT_COUNT_STAR, PT_CUME_DIST, PT_GROUP_CONCAT, PT_GROUPBY_NUM, PT_JSON_ARRAYAGG, PT_JSON_OBJECTAGG, PT_PERCENT_RANK, PT_PERCENTILE_CONT, PT_PERCENTILE_DISC, Q_DISTINCT, qdata_aggregate_multiple_values_to_accumulator(), qdata_calculate_aggregate_cume_dist_percent_rank(), qdata_group_concat_first_value(), qdata_group_concat_value(), qdata_update_agg_interpolation_func_value_and_domain(), qfile_add_item_to_list(), QPROC_IS_INTERPOLATION_FUNC, cubxasl::aggregate_list_node::sort_list, tp_domain_resolve_default(), tp_value_cast(), TYPE_CONSTANT, TYPE_DBVAL, cubxasl::aggregate_accumulator::value, and regu_variable_list_node::value.

Referenced by qexec_end_one_iteration(), qexec_gby_agg_tuple(), and qexec_hash_gby_agg_tuple().

Here is the caller graph for this function:

int qdata_finalize_aggregate_list ( cubthread::entry thread_p,
cubxasl::aggregate_list_node agg_list_p,
bool  keep_list_file 
)

Definition at line 1180 of file query_aggregate.cpp.

References cubxasl::aggregate_list_node::accumulator, ARG_FILE_LINE, assert, ASSERT_ERROR, ASSERT_ERROR_AND_SET, cubxasl::aggregate_accumulator::curr_cnt, pr_type::data_readval(), DB_DEFAULT_PRECISION, DB_DEFAULT_SCALE, db_get_double(), DB_IS_NULL, db_make_double(), db_make_int(), db_make_null(), db_private_free_and_init, db_string_fix_string_size(), DB_TYPE_DOUBLE, DB_TYPE_NUMERIC, DB_TYPE_VARIABLE, db_value_coerce(), db_value_domain_init(), DB_VALUE_DOMAIN_TYPE, qfile_tuple_value_position::dom, cubxasl::aggregate_list_node::domain, db_value::domain, DOMAIN_COMPATIBLE, qfile_tuple_value_type_list::domp, ER_ERROR_SEVERITY, ER_FAILED, ER_GENERIC_ERROR, er_has_error(), er_set(), error(), cubxasl::aggregate_list_node::flag_agg_optimize, cubxasl::aggregate_list_node::function, db_domain_info::general_info, cubxasl::aggregate_list_node::info, cubxasl::aggregate_list_node::list_id, cubxasl::aggregate_list_node::next, NO_ERROR, NULL, cubxasl::aggregate_list_node::option, or_init(), PEEK, sort_list::pos_descr, qfile_tuple_value_position::pos_no, pr_clear_value(), pr_clone_value(), pr_type_from_id(), PT_AVG, PT_COUNT, PT_COUNT_STAR, PT_CUME_DIST, PT_GROUP_CONCAT, PT_GROUPBY_NUM, PT_MAX, PT_MIN, PT_PERCENT_RANK, PT_STDDEV, PT_STDDEV_POP, PT_STDDEV_SAMP, PT_SUM, PT_VAR_POP, PT_VAR_SAMP, PT_VARIANCE, Q_DISTINCT, qdata_add_dbval(), qdata_aggregate_interpolation(), qdata_divide_dbval(), qdata_group_concat_first_value(), qdata_group_concat_value(), qdata_multiply_dbval(), qdata_subtract_dbval(), qfile_close_list(), qfile_close_scan(), qfile_destroy_list(), QFILE_GET_TUPLE_VALUE_FLAG, QFILE_GET_TUPLE_VALUE_LENGTH, qfile_open_list_scan(), qfile_scan_list_next(), qfile_sort_list(), QFILE_TUPLE_LENGTH_SIZE, QFILE_TUPLE_VALUE_HEADER_SIZE, QPROC_IS_INTERPOLATION_FUNC, S_ERROR, S_SUCCESS, pr_type::setval(), cubxasl::aggregate_list_node::sort_list, TP_DOMAIN_COLL_NORMAL, TP_DOMAIN_COLLATION_FLAG, tp_domain_resolve_default(), TP_DOMAIN_TYPE, tp_value_coerce(), qfile_tuple_record::tpl, qfile_list_id::tuple_cnt, tp_domain::type, db_domain_info::general_info::type, qfile_tuple_value_type_list::type_cnt, qfile_list_id::type_list, V_UNBOUND, cubxasl::aggregate_accumulator::value, and cubxasl::aggregate_accumulator::value2.

Referenced by qexec_end_buildvalueblock_iterations(), and qexec_gby_finalize_group().

Here is the caller graph for this function:

int qdata_free_agg_hentry ( const void *  key,
void *  data,
void *  args 
)

Definition at line 2166 of file query_aggregate.cpp.

References NO_ERROR, qdata_free_agg_hkey(), and qdata_free_agg_hvalue().

Referenced by qdata_save_agg_htable_to_list(), qexec_free_agg_hash_context(), and qexec_hash_gby_agg_tuple().

Here is the caller graph for this function:

int qdata_get_agg_hkey_size ( aggregate_hash_key key)

Definition at line 2105 of file query_aggregate.cpp.

References i, NULL, pr_value_mem_size(), cubquery::aggregate_hash_key::val_count, and cubquery::aggregate_hash_key::values.

Referenced by qexec_hash_gby_agg_tuple().

Here is the caller graph for this function:

unsigned int qdata_hash_agg_hkey ( const void *  key,
unsigned int  ht_size 
)

Definition at line 2189 of file query_aggregate.cpp.

References i, mht_get_hash_number(), cubquery::aggregate_hash_key::val_count, and cubquery::aggregate_hash_key::values.

Referenced by qexec_alloc_agg_hash_context().

Here is the caller graph for this function:

SCAN_CODE qdata_load_agg_hentry_from_list ( cubthread::entry thread_p,
qfile_list_scan_id list_scan_id,
aggregate_hash_key key,
aggregate_hash_value value,
tp_domain **  key_dom,
cubxasl::aggregate_accumulator_domain **  acc_dom 
)

Definition at line 2593 of file query_aggregate.cpp.

References NO_ERROR, PEEK, qdata_load_agg_hentry_from_tuple(), qfile_scan_list_next(), S_ERROR, S_SUCCESS, and qfile_tuple_record::tpl.

Referenced by qexec_groupby(), and qexec_locate_agg_hentry_in_list().

Here is the caller graph for this function:

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 
)