42 #define SQUARE(n) ((n)*(n)) 65 #if defined(ENABLE_UNUSED_FUNCTION) 113 int npages, estimated_nobjs;
114 char *class_name =
NULL;
118 int lk_grant_code = 0;
121 thread_p->push_resource_tracks ();
129 thread_p->pop_resource_tracks ();
149 catalog_access_info.
class_oid = class_id_p;
150 catalog_access_info.
dir_oid = &dir_oid;
159 if (cls_info_p ==
NULL)
167 class_name ? class_name :
"*UNKNOWN-CLASS*", class_id_p->
volid, class_id_p->
pageid, class_id_p->
slotid);
226 if (disk_repr_p ==
NULL)
232 npages = estimated_nobjs = 0;
243 if (estimated_nobjs == -1)
257 if (i < disk_repr_p->n_fixed)
259 disk_attr_p = disk_repr_p->
fixed +
i;
266 for (j = 0, btree_stats_p = disk_attr_p->
bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
291 &catalog_access_info);
322 class_name ? class_name :
"*UNKNOWN-CLASS*", class_id_p->
volid, class_id_p->
pageid, class_id_p->
slotid,
330 thread_p->pop_resource_tracks ();
363 char *classname =
NULL;
369 if (mvcc_snapshot ==
NULL)
451 int npages, estimated_nobjs, max_unique_keys;
452 int i, j, k, size, n_attrs, tot_n_btstats, tot_key_info_size;
453 char *buf_p, *start_p;
463 thread_p->push_resource_tracks ();
471 char *class_name =
NULL;
480 class_name ? class_name :
"*UNKNOWN-CLASS*");
482 if (class_name !=
NULL)
494 catalog_access_info.
class_oid = class_id_p;
495 catalog_access_info.
dir_oid = &dir_oid;
502 if (cls_info_p ==
NULL)
507 if (time_stamp > 0 && time_stamp >= cls_info_p->
ci_time_stamp)
519 if (disk_repr_p ==
NULL)
530 tot_n_btstats = tot_key_info_size = 0;
531 for (i = 0; i < n_attrs; i++)
533 if (i < disk_repr_p->n_fixed)
535 disk_attr_p = disk_repr_p->
fixed +
i;
543 for (j = 0, btree_stats_p = disk_attr_p->
bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
568 size += tot_key_info_size;
572 start_p = buf_p = (
char *) malloc (size);
577 memset (start_p, 0, size);
582 npages = estimated_nobjs = max_unique_keys = -1;
597 else if (!use_stat_estimation)
611 if (estimated_nobjs < 0)
619 estimated_nobjs = MAX (estimated_nobjs, cls_info_p->
ci_tot_objects);
635 npages = MAX (npages, 1);
647 for (i = 0; i < n_attrs; i++)
649 if (i < disk_repr_p->n_fixed)
651 disk_attr_p = disk_repr_p->
fixed +
i;
667 for (j = 0, btree_stats_p = disk_attr_p->
bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
672 max_unique_keys = MAX (max_unique_keys, btree_stats_p->
keys);
679 btree_stats_p->
leafs = MAX (1, btree_stats_p->
leafs);
680 btree_stats_p->
pages = MAX (1, btree_stats_p->
pages);
692 npages = btree_stats_p->
pages;
694 npages = MAX (npages, 1);
697 if (npages > btree_stats_p->
pages && use_stat_estimation)
721 if (estimated_nobjs > 0 && use_stat_estimation)
724 btree_stats_p->
keys = MAX (btree_stats_p->
keys, 1);
756 for (k = 0; k < btree_stats_p->
pkeys_size; k++)
759 if (estimated_nobjs > 0 && use_stat_estimation)
762 btree_stats_p->
pkeys[k] = MAX (btree_stats_p->
pkeys[k], 1);
765 if (k + 1 == key_size)
768 btree_stats_p->
pkeys[k] = btree_stats_p->
keys;
785 thread_p->pop_resource_tracks ();
805 thread_p->pop_resource_tracks ();
810 #if defined(ENABLE_UNUSED_FUNCTION) 824 return (*date1_p - *date2_p);
840 return (
int) (*time1_p - *time2_p);
856 return (
int) (*utime1_p - *utime2_p);
872 if (datetime1_p->
date < datetime2_p->
date)
876 else if (datetime1_p->
date > datetime2_p->
date)
880 else if (datetime1_p->
time < datetime2_p->
time)
884 else if (datetime1_p->
time > datetime2_p->
time)
907 double comp_result = money1_p->
amount - money2_p->
amount;
909 if (comp_result == 0.0)
913 else if (comp_result < 0.0)
938 status = ((data1_p->
i < data2_p->
i) ?
DB_LT : ((data1_p->
i > data2_p->
i) ?
DB_GT :
DB_EQ));
950 status = ((data1_p->
f < data2_p->
f) ?
DB_LT : ((data1_p->
f > data2_p->
f) ?
DB_GT :
DB_EQ));
954 status = ((data1_p->
d < data2_p->
d) ?
DB_LT : ((data1_p->
d > data2_p->
d) ?
DB_GT :
DB_EQ));
958 status = stats_compare_date (&data1_p->
date, &data2_p->
date);
962 status = stats_compare_time (&data1_p->
time, &data2_p->
time);
967 status = stats_compare_utime (&data1_p->
utime, &data2_p->
utime);
984 status = stats_compare_money (&data1_p->
money, &data2_p->
money);
1004 return (
unsigned int) time (&tloc);
1007 #if defined(CUBRID_DEBUG) 1018 const char *prefix =
"";
1021 if (class_stats ==
NULL)
1026 fprintf (fpp,
"\nCLASS STATISTICS\n");
1027 fprintf (fpp,
"****************\n");
1029 fprintf (fpp,
" Timestamp: %s", ctime (&tloc));
1030 fprintf (fpp,
" Total Pages in Class Heap: %d\n", class_stats->
heap_num_pages);
1032 fprintf (fpp,
" Number of attributes: %d\n", class_stats->
n_attrs);
1034 for (i = 0; i < class_stats->
n_attrs; i++)
1036 fprintf (fpp,
"\n Attribute :\n");
1037 fprintf (fpp,
" id: %d\n", class_stats->
attr_stats[i].
id);
1038 fprintf (fpp,
" Type: ");
1043 fprintf (fpp,
"DB_TYPE_INTEGER \n");
1047 fprintf (fpp,
"DB_TYPE_BIGINT \n");
1051 fprintf (fpp,
"DB_TYPE_SHORT \n");
1055 fprintf (fpp,
"DB_TYPE_FLOAT \n");
1059 fprintf (fpp,
"DB_TYPE_DOUBLE \n");
1063 fprintf (fpp,
"DB_TYPE_STRING \n");
1067 fprintf (fpp,
"DB_TYPE_OBJECT \n");
1071 fprintf (fpp,
"DB_TYPE_SET \n");
1075 fprintf (fpp,
"DB_TYPE_JSON \n");
1079 fprintf (fpp,
"DB_TYPE_MULTISET \n");
1083 fprintf (fpp,
"DB_TYPE_SEQUENCE \n");
1087 fprintf (fpp,
"DB_TYPE_TIME \n");
1091 fprintf (fpp,
"DB_TYPE_TIMESTAMP \n");
1095 fprintf (fpp,
"DB_TYPE_TIMESTAMPLTZ \n");
1099 fprintf (fpp,
"DB_TYPE_TIMESTAMPTZ \n");
1103 fprintf (fpp,
"DB_TYPE_DATETIME \n");
1107 fprintf (fpp,
"DB_TYPE_DATETIMELTZ \n");
1111 fprintf (fpp,
"DB_TYPE_DATETIMETZ \n");
1115 fprintf (fpp,
"DB_TYPE_MONETARY \n");
1119 fprintf (fpp,
"DB_TYPE_DATE \n");
1123 fprintf (fpp,
"DB_TYPE_BLOB \n");
1127 fprintf (fpp,
"DB_TYPE_CLOB \n");
1131 fprintf (fpp,
"DB_TYPE_VARIABLE \n");
1135 fprintf (fpp,
"DB_TYPE_SUB \n");
1139 fprintf (fpp,
"DB_TYPE_POINTER \n");
1143 fprintf (fpp,
"DB_TYPE_NULL \n");
1147 fprintf (fpp,
"DB_TYPE_NUMERIC \n");
1151 fprintf (fpp,
"DB_TYPE_BIT \n");
1155 fprintf (fpp,
"DB_TYPE_VARBIT \n");
1159 fprintf (fpp,
"DB_TYPE_CHAR \n");
1163 fprintf (fpp,
"DB_TYPE_NCHAR \n");
1167 fprintf (fpp,
"DB_TYPE_VARNCHAR \n");
1174 fprintf (fpp,
" BTree statistics:\n");
1180 fprintf (fpp,
" Cardinality: %d (", bt_statsp->
keys);
1186 fprintf (fpp,
"%s%d", prefix, bt_statsp->
pkeys[k]);
1190 fprintf (fpp,
") ,");
1191 fprintf (fpp,
" Total Pages: %d , Leaf Pages: %d , Height: %d\n", bt_statsp->
pages, bt_statsp->
leafs,
1194 fprintf (fpp,
"\n");
1197 fprintf (fpp,
"\n\n");
1226 int i, j, k, btree_iter, m;
1238 int cls_idx_cache = 0, subcls_idx_cache = 0;
1248 for (i = 0; i < partitions_count; i++)
1263 catalog_access_info.
class_oid = class_id_p;
1264 catalog_access_info.
dir_oid = &dir_oid;
1272 if (cls_info_p ==
NULL)
1288 if (disk_repr_p ==
NULL)
1300 if (i < disk_repr_p->n_fixed)
1302 disk_attr_p = disk_repr_p->
fixed +
i;
1309 for (j = 0, btree_stats_p = disk_attr_p->
bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
1343 if (i < disk_repr_p->n_fixed)
1345 disk_attr_p = disk_repr_p->
fixed +
i;
1352 for (j = 0, btree_stats_p = disk_attr_p->
bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
1355 mean[btree_iter].
pkeys =
1356 (
double *)
db_private_alloc (thread_p, mean[btree_iter].pkeys_size *
sizeof (
double));
1357 if (mean[btree_iter].pkeys ==
NULL)
1362 memset (mean[btree_iter].pkeys, 0, mean[btree_iter].pkeys_size *
sizeof (
double));
1364 stddev[btree_iter].pkeys_size = btree_stats_p->
pkeys_size;
1365 stddev[btree_iter].pkeys =
1366 (
double *)
db_private_alloc (thread_p, mean[btree_iter].pkeys_size *
sizeof (
double));
1367 if (stddev[btree_iter].pkeys ==
NULL)
1372 memset (stddev[btree_iter].pkeys, 0, mean[btree_iter].pkeys_size *
sizeof (
double));
1383 if (cls_rep ==
NULL)
1389 for (i = 0; i < partitions_count; i++)
1392 if (subcls_info !=
NULL)
1396 if (subcls_disk_rep !=
NULL)
1400 if (subcls_rep !=
NULL)
1412 part_catalog_access_info.
class_oid = &partitions[
i];
1413 part_catalog_access_info.
dir_oid = &part_dir_oid;
1422 if (subcls_info ==
NULL)
1438 &part_catalog_access_info);
1439 if (subcls_disk_rep ==
NULL)
1448 if (subcls_rep ==
NULL)
1457 for (j = 0; j < subcls_disk_rep->n_fixed + subcls_disk_rep->n_variable; j++)
1459 if (j < subcls_disk_rep->n_fixed)
1461 subcls_attr_p = subcls_disk_rep->fixed + j;
1462 disk_attr_p = disk_repr_p->
fixed + j;
1466 subcls_attr_p = subcls_disk_rep->variable + (j - subcls_disk_rep->n_fixed);
1471 if (subcls_attr_p->id != disk_attr_p->
id || subcls_attr_p->n_btstats != disk_attr_p->
n_btstats)
1480 for (k = 0, btree_stats_p = disk_attr_p->
bt_stats; k < disk_attr_p->n_btstats; k++, btree_stats_p++)
1485 &btree_stats_p->
btid);
1486 if (subcls_stats ==
NULL)
1492 mean[btree_iter].
leafs += subcls_stats->
leafs;
1494 mean[btree_iter].
pages += subcls_stats->
pages;
1498 mean[btree_iter].
keys += subcls_stats->
keys;
1501 for (m = 0; m < subcls_stats->
pkeys_size; m++)
1503 mean[btree_iter].
pkeys[m] += subcls_stats->
pkeys[m];
1512 for (btree_iter = 0; btree_iter < n_btrees; btree_iter++)
1514 mean[btree_iter].
leafs /= partitions_count;
1516 mean[btree_iter].
pages /= partitions_count;
1518 mean[btree_iter].
height /= partitions_count;
1520 mean[btree_iter].
keys /= partitions_count;
1523 for (m = 0; m < mean[btree_iter].
pkeys_size; m++)
1525 mean[btree_iter].
pkeys[m] /= partitions_count;
1529 for (i = 0; i < partitions_count; i++)
1534 if (subcls_disk_rep !=
NULL)
1538 if (subcls_rep !=
NULL)
1549 part_catalog_access_info.
class_oid = &partitions[
i];
1550 part_catalog_access_info.
dir_oid = &part_dir_oid;
1565 &part_catalog_access_info);
1566 if (subcls_disk_rep ==
NULL)
1574 if (subcls_rep ==
NULL)
1582 for (j = 0; j < subcls_disk_rep->n_fixed + subcls_disk_rep->n_variable; j++)
1584 if (j < subcls_disk_rep->n_fixed)
1586 subcls_attr_p = subcls_disk_rep->fixed + j;
1587 disk_attr_p = disk_repr_p->
fixed + j;
1591 subcls_attr_p = subcls_disk_rep->variable + (j - subcls_disk_rep->n_fixed);
1596 if (subcls_attr_p->id != disk_attr_p->
id || subcls_attr_p->n_btstats != disk_attr_p->
n_btstats)
1606 for (k = 0, btree_stats_p = disk_attr_p->
bt_stats; k < disk_attr_p->n_btstats; k++, btree_stats_p++)
1611 &btree_stats_p->
btid);
1612 if (subcls_stats ==
NULL)
1618 stddev[btree_iter].leafs +=
SQUARE (btree_stats_p->
leafs - mean[btree_iter].
leafs);
1620 stddev[btree_iter].pages +=
SQUARE (subcls_stats->
pages - mean[btree_iter].
pages);
1622 stddev[btree_iter].height +=
SQUARE (subcls_stats->
height - mean[btree_iter].
height);
1624 stddev[btree_iter].keys +=
SQUARE (subcls_stats->
keys - mean[btree_iter].
keys);
1627 for (m = 0; m < subcls_stats->
pkeys_size; m++)
1629 stddev[btree_iter].pkeys[m] +=
SQUARE (subcls_stats->
pkeys[m] - mean[btree_iter].
pkeys[m]);
1637 for (btree_iter = 0; btree_iter < n_btrees; btree_iter++)
1639 stddev[btree_iter].leafs = sqrt (stddev[btree_iter].leafs / partitions_count);
1641 stddev[btree_iter].pages = sqrt (stddev[btree_iter].pages / partitions_count);
1643 stddev[btree_iter].height = sqrt (stddev[btree_iter].height / partitions_count);
1645 stddev[btree_iter].keys = sqrt (stddev[btree_iter].keys / partitions_count);
1648 for (m = 0; m < mean[btree_iter].
pkeys_size; m++)
1650 stddev[btree_iter].pkeys[m] = sqrt (stddev[btree_iter].pkeys[m] / partitions_count);
1658 if (i < disk_repr_p->n_fixed)
1660 disk_attr_p = disk_repr_p->
fixed +
i;
1667 for (j = 0, btree_stats_p = disk_attr_p->
bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
1669 if (mean[btree_iter].leafs != 0)
1671 btree_stats_p->
leafs =
1672 (int) (mean[btree_iter].leafs * (1 + stddev[btree_iter].leafs / mean[btree_iter].leafs));
1674 if (mean[btree_iter].pages != 0)
1676 btree_stats_p->
pages =
1677 (int) (mean[btree_iter].pages * (1 + stddev[btree_iter].pages / mean[btree_iter].pages));
1679 if (mean[btree_iter].height != 0)
1682 (int) (mean[btree_iter].height * (1 + stddev[btree_iter].height / mean[btree_iter].height));
1684 if (mean[btree_iter].keys != 0)
1686 btree_stats_p->
keys =
1687 (int) (mean[btree_iter].keys * (1 + stddev[btree_iter].keys / mean[btree_iter].keys));
1691 for (m = 0; m < mean[btree_iter].
pkeys_size; m++)
1693 if (mean[btree_iter].pkeys[m] != 0)
1695 btree_stats_p->
pkeys[m] =
1696 (int) (mean[btree_iter].pkeys[m] * (1 + stddev[btree_iter].pkeys[m] / mean[btree_iter].pkeys[m]));
1712 &catalog_access_info);
1726 if (cls_rep !=
NULL)
1730 if (subcls_rep !=
NULL)
1736 for (i = 0; i < n_btrees; i++)
1738 if (mean[i].pkeys !=
NULL)
1747 for (i = 0; i < n_btrees; i++)
1749 if (stddev[i].pkeys !=
NULL)
1760 if (subcls_disk_rep !=
NULL)
1764 if (cls_info_p !=
NULL)
1768 if (disk_repr_p !=
NULL)
1790 const char *cls_btname =
NULL;
1795 for (i = 0; i < cls_rep->
n_indexes; i++)
1804 if (cls_btname ==
NULL)
1812 for (i = 0; i < subcls_rep->
n_indexes; i++)
1814 if (strcasecmp (cls_btname, subcls_rep->
indexes[i].
btname) == 0)
1821 if (subcls_btid ==
NULL)
1828 for (i = 0, btstats = subcls_attr->
bt_stats; i < subcls_attr->n_btstats; i++, btstats++)
#define OR_BTID_ALIGNED_SIZE
CLS_INFO * catalog_get_class_info(THREAD_ENTRY *thread_p, OID *class_id_p, CATALOG_ACCESS_INFO *catalog_access_info_p)
MVCC_SNAPSHOT * logtb_get_mvcc_snapshot(THREAD_ENTRY *thread_p)
int btree_get_stats(THREAD_ENTRY *thread_p, BTREE_STATS *stat_info_p, bool with_fullscan)
int partition_get_partition_oids(THREAD_ENTRY *thread_p, const OID *class_oid, OID **partition_oids, int *count)
int catalog_add_class_info(THREAD_ENTRY *thread_p, OID *class_id_p, CLS_INFO *class_info_p, CATALOG_ACCESS_INFO *catalog_access_info_p)
struct tp_domain * setdomain
static int stats_update_partitioned_statistics(THREAD_ENTRY *thread_p, OID *class_oid, OID *partitions, int count, bool with_fullscan)
int xbtree_get_unique_pk(THREAD_ENTRY *thread_p, BTID *btid)
#define ASSERT_ERROR_AND_SET(error_code)
#define ER_UPDATE_STAT_CANNOT_GET_LOCK
#define assert_release(e)
unsigned int ci_time_stamp
int lock_object(THREAD_ENTRY *thread_p, const OID *oid, const OID *class_oid, LOCK lock, int cond_flag)
#define OID_SET_NULL(oidp)
#define BTID_IS_EQUAL(b1, b2)
int or_packed_domain_size(struct tp_domain *domain, int include_classoids)
int heap_scancache_end(THREAD_ENTRY *thread_p, HEAP_SCANCACHE *scan_cache)
#define CATALOG_ACCESS_INFO_INITIALIZER
#define ER_LOG_FINISHED_TO_UPDATE_STATISTICS
int catalog_start_access_with_dir_oid(THREAD_ENTRY *thread_p, CATALOG_ACCESS_INFO *catalog_access_info, LOCK lock_mode)
#define VFID_ISNULL(vfid_ptr)
int heap_scancache_start(THREAD_ENTRY *thread_p, HEAP_SCANCACHE *scan_cache, const HFID *hfid, const OID *class_oid, int cache_last_fix_page, int is_indexscan, MVCC_SNAPSHOT *mvcc_snapshot)
int boot_find_root_heap(HFID *root_hfid_p)
#define RECDES_INITIALIZER
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int catalog_end_access_with_dir_oid(THREAD_ENTRY *thread_p, CATALOG_ACCESS_INFO *catalog_access_info, int error)
int file_get_num_user_pages(THREAD_ENTRY *thread_p, const VFID *vfid, int *n_user_pages_out)
int xstats_update_all_statistics(THREAD_ENTRY *thread_p, bool with_fullscan)
int tp_domain_size(const TP_DOMAIN *domain)
#define BTREE_STATS_PKEYS_NUM
void lock_unlock_object(THREAD_ENTRY *thread_p, const OID *oid, const OID *class_oid, LOCK lock, bool force)
unsigned int stats_get_time_stamp(void)
#define heap_classrepr_free_and_init(class_repr, idxp)
int catalog_add_representation(THREAD_ENTRY *thread_p, OID *class_id_p, REPR_ID repr_id, DISK_REPR *disk_repr_p, OID *rep_dir_p, CATALOG_ACCESS_INFO *catalog_access_info_p)
#define TP_DOMAIN_TYPE(dom)
static void cleanup(int signo)
struct disk_attribute * variable
DB_TIMESTAMPTZ timestamptz
int heap_estimate_num_objects(THREAD_ENTRY *thread_p, const HFID *hfid)
#define db_private_free_and_init(thrd, ptr)
#define OR_PUT_BTID(ptr, btid)
int catalog_get_dir_oid_from_cache(THREAD_ENTRY *thread_p, const OID *class_id_p, OID *dir_oid_p)
#define db_private_free(thrd, ptr)
#define db_private_alloc(thrd, size)
struct disk_attribute * fixed
OR_CLASSREP * heap_classrepr_get(THREAD_ENTRY *thread_p, const OID *class_oid, RECDES *class_recdes, REPR_ID reprid, int *idx_incache)
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
static void error(const char *msg)
char * xstats_get_statistics_from_server(THREAD_ENTRY *thread_p, OID *class_id_p, unsigned int time_stamp, int *length_p)
int xstats_update_statistics(THREAD_ENTRY *thread_p, OID *class_id_p, bool with_fullscan)
#define HFID_IS_NULL(hfid)
int catalog_get_last_representation_id(THREAD_ENTRY *thread_p, OID *class_oid_p, REPR_ID *repr_id_p)
char * or_class_name(RECDES *record)
#define ER_SP_UNKNOWN_SLOTID
#define free_and_init(ptr)
char * or_pack_domain(char *ptr, struct tp_domain *domain, int include_classoids, int is_null)
bool prm_get_bool_value(PARAM_ID prm_id)
#define OR_PUT_INT(ptr, val)
#define ER_LOG_STARTED_TO_UPDATE_STATISTICS
#define BTID_IS_NULL(btid)
#define catalog_free_class_info_and_init(class_info_p)
SCAN_CODE heap_next(THREAD_ENTRY *thread_p, const HFID *hfid, OID *class_oid, OID *next_oid, RECDES *recdes, HEAP_SCANCACHE *scan_cache, int ispeeking)
int heap_get_class_name(THREAD_ENTRY *thread_p, const OID *class_oid, char **class_name)
#define catalog_free_representation_and_init(repr_p)
const BTREE_STATS * stats_find_inherited_index_stats(OR_CLASSREP *cls_rep, OR_CLASSREP *subcls_rep, DISK_ATTR *subcls_attr, BTID *cls_btid)
DISK_REPR * catalog_get_representation(THREAD_ENTRY *thread_p, OID *class_id_p, REPR_ID repr_id, CATALOG_ACCESS_INFO *catalog_access_info_p)