CUBRID Engine  latest
db_query.c File Reference
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "db_query.h"
#include "error_manager.h"
#include "storage_common.h"
#include "object_representation.h"
#include "object_primitive.h"
#include "db.h"
#include "schema_manager.h"
#include "server_interface.h"
#include "system_parameter.h"
#include "xasl_generation.h"
#include "network_interface_cl.h"
#include "transaction_cl.h"
#include "dbtype.h"
Include dependency graph for db_query.c:

Go to the source code of this file.

Classes

struct  alloc_resource
 

Macros

#define DB_OID_INCLUDED(r)   ((r)->oid_included == true)
 
#define DB_INVALID_INDEX(i, cnt)   ((i) < 0 || (i) >= (cnt))
 
#define DB_INVALID_RESTYPE(t)
 
#define PLAN_BUF_INITIAL_LENGTH   (1024)
 

Functions

static DB_QUERY_RESULTallocate_query_result (void)
 
static void free_query_result (DB_QUERY_RESULT *q_res)
 
static DB_QUERY_TYPEdb_cp_query_type_helper (DB_QUERY_TYPE *src, DB_QUERY_TYPE *dest)
 
static int or_packed_query_format_size (const DB_QUERY_TYPE *q, int *count)
 
static char * or_pack_query_format (char *buf, const DB_QUERY_TYPE *q, const int count)
 
static char * or_unpack_query_format (char *buf, DB_QUERY_TYPE **q)
 
void db_free_query_format (DB_QUERY_TYPE *q)
 
void db_init_prepare_info (DB_PREPARE_INFO *info)
 
int db_pack_prepare_info (const DB_PREPARE_INFO *info, char **buffer)
 
int db_unpack_prepare_info (DB_PREPARE_INFO *info, char *buffer)
 
void db_free_query_result (DB_QUERY_RESULT *r)
 
DB_QUERY_TYPEdb_alloc_query_format (int cnt)
 
DB_QUERY_RESULTdb_alloc_query_result (DB_RESULT_TYPE r_type, int col_cnt)
 
void db_init_query_result (DB_QUERY_RESULT *r, DB_RESULT_TYPE r_type)
 
void db_clear_client_query_result (int notify_server, bool end_holdable)
 
DB_QUERY_TYPEdb_cp_query_type (DB_QUERY_TYPE *query_type, int copy_only_user)
 
int db_execute_with_values (const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error, int arg_count, DB_VALUE *vals)
 
int db_get_query_format (const char *CSQL_query, DB_QUERY_TYPE **result, DB_QUERY_ERROR *query_error)
 
DB_QUERY_TYPEdb_query_format_next (DB_QUERY_TYPE *query_type)
 
DB_COL_TYPE db_query_format_col_type (DB_QUERY_TYPE *query_type)
 
char * db_query_format_name (DB_QUERY_TYPE *query_type)
 
char * db_query_format_attr_name (DB_QUERY_TYPE *query_type)
 
char * db_query_format_spec_name (DB_QUERY_TYPE *query_type)
 
char * db_query_format_original_name (DB_QUERY_TYPE *query_type)
 
SM_DOMAINdb_query_format_domain (DB_QUERY_TYPE *query_type)
 
SM_DOMAINdb_query_format_src_domain (DB_QUERY_TYPE *query_type)
 
DB_TYPE db_query_format_type (DB_QUERY_TYPE *query_type)
 
int db_query_format_size (DB_QUERY_TYPE *query_type)
 
void db_query_format_free (DB_QUERY_TYPE *query_type)
 
const char * db_query_format_class_name (DB_QUERY_TYPE *query_type)
 
int db_query_format_is_non_null (DB_QUERY_TYPE *query_type)
 
int db_query_execute (const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error)
 
int db_execute (const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error)
 
int db_execute_oid (const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error)
 
DB_QUERY_RESULTdb_get_db_value_query_result (DB_VALUE *val)
 
int db_get_query_result_format (DB_QUERY_RESULT *result, DB_QUERY_TYPE **type_list)
 
int db_query_next_tuple (DB_QUERY_RESULT *result)
 
int db_query_prev_tuple (DB_QUERY_RESULT *result)
 
int db_query_first_tuple (DB_QUERY_RESULT *result)
 
int db_query_last_tuple (DB_QUERY_RESULT *result)
 
int db_query_seek_tuple (DB_QUERY_RESULT *result, int offset, int seek_mode)
 
DB_QUERY_TPLPOSdb_query_get_tplpos (DB_QUERY_RESULT *result)
 
int db_query_set_tplpos (DB_QUERY_RESULT *result, DB_QUERY_TPLPOS *tplpos)
 
void db_query_free_tplpos (DB_QUERY_TPLPOS *tplpos)
 
int db_query_get_tuple_value (DB_QUERY_RESULT *result, int index, DB_VALUE *value)
 
int db_query_get_tuple_value_by_name (DB_QUERY_RESULT *result, char *column_name, DB_VALUE *value)
 
int db_query_get_tuple_valuelist (DB_QUERY_RESULT *result, int size, DB_VALUE *value_list)
 
int db_query_tuple_count (DB_QUERY_RESULT *result)
 
int db_query_column_count (DB_QUERY_RESULT *result)
 
int db_query_get_tuple_oid (DB_QUERY_RESULT *result, DB_VALUE *db_value)
 
int db_query_end (DB_QUERY_RESULT *result)
 
int db_query_set_copy_tplvalue (DB_QUERY_RESULT *result, int copy)
 
bool db_is_client_cache_reusable (DB_QUERY_RESULT *result)
 
int db_query_get_cache_time (DB_QUERY_RESULT *result, CACHE_TIME *cache_time)
 
int db_query_end_internal (DB_QUERY_RESULT *result, bool notify_server)
 
int db_query_prefetch_columns (DB_QUERY_RESULT *result, int *columns, int col_count)
 
int db_query_plan_dump_file (char *filename)
 
void db_set_execution_plan (char *plan, int length)
 
char * db_get_execution_plan (void)
 
void db_free_execution_plan (void)
 

Variables

struct {
   int   qres_cnt
 
   int   qres_closed_cnt
 
   int   entry_cnt
 
   DB_QUERY_RESULT **   qres_list
 
   struct alloc_resource   alloc_res
 
Qres_table
 
static const int QP_QRES_LIST_INIT_CNT = 10
 
static const float QP_QRES_LIST_INC_RATE = 1.25f
 
static char * db_Execution_plan = NULL
 
static int db_Execution_plan_length = -1
 

Macro Definition Documentation

#define DB_INVALID_INDEX (   i,
  cnt 
)    ((i) < 0 || (i) >= (cnt))
#define DB_INVALID_RESTYPE (   t)
Value:
((t) != T_SELECT && \
(t) != T_CALL && \
(t) != T_OBJFETCH && \
(t) != T_GET)

Definition at line 48 of file db_query.c.

Referenced by db_alloc_query_result(), db_init_query_result(), db_query_column_count(), and db_query_get_tuple_oid().

#define DB_OID_INCLUDED (   r)    ((r)->oid_included == true)
#define PLAN_BUF_INITIAL_LENGTH   (1024)

Definition at line 54 of file db_query.c.

Referenced by db_set_execution_plan().

Function Documentation

static DB_QUERY_RESULT * allocate_query_result ( void  )
static

Definition at line 101 of file db_query.c.

References ARG_FILE_LINE, DB_SIZEOF, ER_ERROR_SEVERITY, ER_OUT_OF_VIRTUAL_MEMORY, er_set(), db_query_result::next, NULL, and Qres_table.

Referenced by db_alloc_query_result().

Here is the caller graph for this function:

void db_clear_client_query_result ( int  notify_server,
bool  end_holdable 
)

Definition at line 1208 of file db_query.c.

References db_query_end_internal(), NULL, Qres_table, and T_SELECT.

Referenced by tran_2pc_prepare(), tran_2pc_prepare_global_tran(), tran_abort(), tran_abort_only_client(), and tran_commit().

Here is the caller graph for this function:

int db_execute_with_values ( const char *  CSQL_query,
DB_QUERY_RESULT **  result,
DB_QUERY_ERROR query_error,
int  arg_count,
DB_VALUE vals 
)
void db_free_execution_plan ( void  )

Definition at line 3638 of file db_query.c.

References db_Execution_plan, db_Execution_plan_length, free_and_init, and NULL.

Referenced by db_shutdown().

Here is the caller graph for this function:

char* db_get_execution_plan ( void  )

Definition at line 3621 of file db_query.c.

References db_Execution_plan, and NULL.

Referenced by fn_execute_array(), and fn_execute_internal().

Here is the caller graph for this function:

int db_get_query_format ( const char *  CSQL_query,
DB_QUERY_TYPE **  result,
DB_QUERY_ERROR query_error 
)

Definition at line 1558 of file db_query.c.

References db_compile_and_execute_queries_internal(), DB_NO_OIDS, error(), and NO_ERROR.

bool db_is_client_cache_reusable ( DB_QUERY_RESULT result)

Definition at line 3432 of file db_query.c.

References T_CACHE_HIT, and db_query_result::type.

Referenced by ux_execute(), and ux_execute_all().

Here is the caller graph for this function:

int db_query_execute ( const char *  CSQL_query,
DB_QUERY_RESULT **  result,
DB_QUERY_ERROR query_error 
)

Definition at line 1808 of file db_query.c.

References db_compile_and_execute_queries_internal(), DB_NO_OIDS, error(), and NO_ERROR.

char* db_query_format_attr_name ( DB_QUERY_TYPE query_type)

Definition at line 1622 of file db_query.c.

References db_query_type::attr_name, and CHECK_1ARG_NULL.

Referenced by prepare_column_list_info_set().

Here is the caller graph for this function:

const char* db_query_format_class_name ( DB_QUERY_TYPE query_type)

Definition at line 1740 of file db_query.c.

References CHECK_1ARG_NULL, tp_domain::class_mop, db_get_class_name(), db_query_format_src_domain(), and NULL.

Referenced by prepare_column_list_info_set(), and ux_make_out_rs().

Here is the caller graph for this function:

DB_COL_TYPE db_query_format_col_type ( DB_QUERY_TYPE query_type)

Definition at line 1590 of file db_query.c.

References CHECK_1ARG_RETURN_EXPR, db_query_type::col_type, and DB_COL_OTHER.

Referenced by prepare_column_list_info_set().

Here is the caller graph for this function:

SM_DOMAIN* db_query_format_domain ( DB_QUERY_TYPE query_type)

Definition at line 1661 of file db_query.c.

References CHECK_1ARG_NULL, and db_query_type::domain.

Referenced by copy_column_spec_to_sqlda(), prepare_column_list_info_set(), and ux_make_out_rs().

Here is the caller graph for this function:

void db_query_format_free ( DB_QUERY_TYPE query_type)

Definition at line 1723 of file db_query.c.

References db_free_query_format(), and NULL.

Referenced by alloc_dynamic(), free_attr_spec(), free_dynamic(), hm_qresult_end(), prepare_column_list_info_set(), uci_object_describe(), and uci_prepare().

Here is the caller graph for this function:

int db_query_format_is_non_null ( DB_QUERY_TYPE query_type)
char* db_query_format_original_name ( DB_QUERY_TYPE query_type)

Definition at line 1648 of file db_query.c.

References CHECK_1ARG_NULL, and db_query_type::original_name.

Referenced by prepare_column_list_info_set(), and ux_make_out_rs().

Here is the caller graph for this function:

int db_query_format_size ( DB_QUERY_TYPE query_type)

Definition at line 1704 of file db_query.c.

References CHECK_1ARG_MINUSONE, and db_query_type::size.

Referenced by copy_column_spec_to_sqlda().

Here is the caller graph for this function:

char* db_query_format_spec_name ( DB_QUERY_TYPE query_type)

Definition at line 1635 of file db_query.c.

References CHECK_1ARG_NULL, and db_query_type::spec_name.

SM_DOMAIN* db_query_format_src_domain ( DB_QUERY_TYPE query_type)

Definition at line 1675 of file db_query.c.

References CHECK_1ARG_NULL, and db_query_type::src_domain.

Referenced by db_query_format_class_name(), and db_query_format_is_non_null().

Here is the caller graph for this function:

DB_TYPE db_query_format_type ( DB_QUERY_TYPE query_type)

Definition at line 1690 of file db_query.c.

References CHECK_1ARG_RETURN_EXPR, db_query_type::db_type, and DB_TYPE_NULL.

Referenced by csql_results().

Here is the caller graph for this function:

void db_query_free_tplpos ( DB_QUERY_TPLPOS tplpos)

Definition at line 2858 of file db_query.c.

References free_and_init.

Referenced by db_query_seek_tuple().

Here is the caller graph for this function:

int db_query_get_cache_time ( DB_QUERY_RESULT result,
CACHE_TIME cache_time 
)

Definition at line 3451 of file db_query.c.

References db_select_result::cache_time, CACHE_TIME_RESET, NO_ERROR, NULL, db_query_result::res, db_query_result::s, db_query_result::status, T_CLOSED, T_SELECT, and db_query_result::type.

Referenced by execute_info_set().

Here is the caller graph for this function:

int db_query_get_tuple_value ( DB_QUERY_RESULT result,
int  index,
DB_VALUE value 
)
int db_query_plan_dump_file ( char *  filename)

Definition at line 3541 of file db_query.c.

References NO_ERROR, NULL, query_Plan_dump_filename, and strdup().

Referenced by cas_log_query_info_init().

Here is the caller graph for this function:

int db_query_prefetch_columns ( DB_QUERY_RESULT result,
int *  columns,
int  col_count 
)
void db_set_execution_plan ( char *  plan,
int  length 
)
static void free_query_result ( DB_QUERY_RESULT q_res)
static

Definition at line 131 of file db_query.c.

References free_and_init, db_query_result::next, and Qres_table.

Referenced by db_free_query_result().

Here is the caller graph for this function:

static int or_packed_query_format_size ( const DB_QUERY_TYPE q,
int *  count 
)
static

Variable Documentation

struct alloc_resource alloc_res

Definition at line 71 of file db_query.c.

char* db_Execution_plan = NULL
static

Definition at line 84 of file db_query.c.

Referenced by db_free_execution_plan(), db_get_execution_plan(), and db_set_execution_plan().

int db_Execution_plan_length = -1
static

Definition at line 85 of file db_query.c.

Referenced by db_free_execution_plan(), and db_set_execution_plan().

int entry_cnt

Definition at line 69 of file db_query.c.

const float QP_QRES_LIST_INC_RATE = 1.25f
static

Definition at line 81 of file db_query.c.

Referenced by db_alloc_query_result().

const int QP_QRES_LIST_INIT_CNT = 10
static

Definition at line 79 of file db_query.c.

Referenced by db_alloc_query_result().

int qres_closed_cnt

Definition at line 68 of file db_query.c.

int qres_cnt

Definition at line 67 of file db_query.c.

DB_QUERY_RESULT** qres_list

Definition at line 70 of file db_query.c.

struct { ... } Qres_table