Skip to content

Commit

Permalink
[CBRD-24559] Use the number of unique index keys as number of objects…
Browse files Browse the repository at this point in the history
… for statistics. (CUBRID#3947)

http://jira.cubrid.org/browse/CBRD-24559

Use the number of unique index keys as number of objects for statistics. This is to reduce the performance degradation that occurs in the entire heap scan.

I delete existing routines related to unique index keys in get_statistics_from_server ().
  • Loading branch information
shparkcubrid authored Nov 22, 2022
1 parent 70e5245 commit e6cdfce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
9 changes: 0 additions & 9 deletions src/storage/statistics_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ stats_client_unpack_statistics (char *buf_p)
CLASS_STATS *class_stats_p;
ATTR_STATS *attr_stats_p;
BTREE_STATS *btree_stats_p;
int max_unique_keys;
int i, j, k;

if (buf_p == NULL)
Expand Down Expand Up @@ -217,14 +216,6 @@ stats_client_unpack_statistics (char *buf_p)
}
}

/* correct estimated num_objects with unique keys */
max_unique_keys = OR_GET_INT (buf_p);
buf_p += OR_INT_SIZE;
if (max_unique_keys > 0)
{
class_stats_p->heap_num_objects = max_unique_keys;
}

/* validate key stats info */
assert (class_stats_p->heap_num_objects >= 0);
for (i = 0, attr_stats_p = class_stats_p->attr_stats; i < class_stats_p->n_attrs; i++, attr_stats_p++)
Expand Down
49 changes: 28 additions & 21 deletions src/storage/statistics_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ xstats_update_statistics (THREAD_ENTRY * thread_p, OID * class_id_p, bool with_f
OID *partitions = NULL;
int count = 0, error_code = NO_ERROR;
int lk_grant_code = 0;
int nobjs_from_unique_index = 0;
CATALOG_ACCESS_INFO catalog_access_info = CATALOG_ACCESS_INFO_INITIALIZER;

thread_p->push_resource_tracks ();
Expand Down Expand Up @@ -229,14 +230,7 @@ xstats_update_statistics (THREAD_ENTRY * thread_p, OID * class_id_p, bool with_f
}
(void) catalog_end_access_with_dir_oid (thread_p, &catalog_access_info, NO_ERROR);

/* get npages and nobjs. do not use estimation, get correct info */
npages = nobjs = length = 0;
heap_get_num_objects (thread_p, &(cls_info_p->ci_hfid), &npages, &nobjs, &length);
cls_info_p->ci_tot_pages = MAX (npages, 0);
cls_info_p->ci_tot_objects = MAX (nobjs, 0);

/* update the index statistics for each attribute */

for (i = 0; i < disk_repr_p->n_fixed + disk_repr_p->n_variable; i++)
{
if (i < disk_repr_p->n_fixed)
Expand All @@ -259,10 +253,35 @@ xstats_update_statistics (THREAD_ENTRY * thread_p, OID * class_id_p, bool with_f
goto error;
}

/* check using nobjs from unique index */
if (xbtree_get_unique_pk (thread_p, &btree_stats_p->btid))
{
nobjs_from_unique_index = MAX (nobjs_from_unique_index, btree_stats_p->keys);
}

assert_release (btree_stats_p->keys >= 0);
} /* for (j = 0; ...) */
} /* for (i = 0; ...) */

/* get npages and nobjs. do not use estimation, get correct info */
npages = nobjs = length = 0;
if (nobjs_from_unique_index > 0)
{
/* use number of unique index key */
nobjs = nobjs_from_unique_index;
if (file_get_num_user_pages (thread_p, &(cls_info_p->ci_hfid.vfid), &npages) != NO_ERROR)
{
goto error;
}
}
else
{
/* full scan for number of object */
heap_get_num_objects (thread_p, &(cls_info_p->ci_hfid), &npages, &nobjs, &length);
}
cls_info_p->ci_tot_pages = MAX (npages, 0);
cls_info_p->ci_tot_objects = MAX (nobjs, 0);

error_code = catalog_start_access_with_dir_oid (thread_p, &catalog_access_info, X_LOCK);
if (error_code != NO_ERROR)
{
Expand Down Expand Up @@ -433,7 +452,7 @@ xstats_get_statistics_from_server (THREAD_ENTRY * thread_p, OID * class_id_p, un
DISK_ATTR *disk_attr_p;
BTREE_STATS *btree_stats_p;
OID dir_oid;
int npages, estimated_nobjs, max_unique_keys;
int npages, estimated_nobjs;
int i, j, k, size, n_attrs, tot_n_btstats, tot_key_info_size;
char *buf_p, *start_p;
int key_size;
Expand Down Expand Up @@ -552,8 +571,6 @@ xstats_get_statistics_from_server (THREAD_ENTRY * thread_p, OID * class_id_p, un

size += tot_key_info_size; /* key_type, pkeys[] of BTREE_STATS */

size += OR_INT_SIZE; /* max_unique_keys */

start_p = buf_p = (char *) malloc (size);
if (buf_p == NULL)
{
Expand All @@ -564,7 +581,7 @@ xstats_get_statistics_from_server (THREAD_ENTRY * thread_p, OID * class_id_p, un
OR_PUT_INT (buf_p, cls_info_p->ci_time_stamp);
buf_p += OR_INT_SIZE;

npages = estimated_nobjs = max_unique_keys = -1;
npages = estimated_nobjs = -1;

assert (cls_info_p->ci_tot_objects >= 0);
assert (cls_info_p->ci_tot_pages >= 0);
Expand Down Expand Up @@ -651,12 +668,6 @@ xstats_get_statistics_from_server (THREAD_ENTRY * thread_p, OID * class_id_p, un

for (j = 0, btree_stats_p = disk_attr_p->bt_stats; j < disk_attr_p->n_btstats; j++, btree_stats_p++)
{
/* collect maximum unique keys info */
if (xbtree_get_unique_pk (thread_p, &btree_stats_p->btid))
{
max_unique_keys = MAX (max_unique_keys, btree_stats_p->keys);
}

OR_PUT_BTID (buf_p, &btree_stats_p->btid);
buf_p += OR_BTID_ALIGNED_SIZE;

Expand Down Expand Up @@ -758,10 +769,6 @@ xstats_get_statistics_from_server (THREAD_ENTRY * thread_p, OID * class_id_p, un
}
} /* for (j = 0, ...) */
}

OR_PUT_INT (buf_p, max_unique_keys);
buf_p += OR_INT_SIZE;

catalog_free_representation_and_init (disk_repr_p);
catalog_free_class_info_and_init (cls_info_p);

Expand Down

0 comments on commit e6cdfce

Please sign in to comment.