Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25728] Support parallel sort for ORDER_BY #5694

Open
wants to merge 61 commits into
base: feature/parallel_sort
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f92d4ba
Remove previous parallel routines. Add single thread sort routines ex…
shparkcubrid Jul 1, 2024
3387562
remove px_mtx, add list_file_close() for avoiding latch contention, c…
shparkcubrid Jul 3, 2024
def6734
indent
shparkcubrid Jul 3, 2024
9ece22e
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Jul 3, 2024
a0d70d0
init record
shparkcubrid Jul 5, 2024
11f0192
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Jul 8, 2024
743743d
temporarily blocked
shparkcubrid Jul 8, 2024
efbbbff
temporarily, close and reopen temp file for getting.
shparkcubrid Jul 8, 2024
6d4ed79
reopen temp file for getting
shparkcubrid Jul 9, 2024
5a52af4
temporarily split list file on half and remove some assert. it should…
shparkcubrid Jul 16, 2024
01c518f
copy sort_param and split input_temp_file
shparkcubrid Sep 5, 2024
d0ac831
add sort_merge_run_for_parallel ()
shparkcubrid Sep 11, 2024
3243445
add thread wait
shparkcubrid Sep 12, 2024
b24ae69
fix memory leak
shparkcubrid Sep 12, 2024
997279d
fix big tuple
shparkcubrid Sep 12, 2024
e83bc14
slip
shparkcubrid Sep 25, 2024
840b4aa
init prev page_id of first page when input file is splitted
shparkcubrid Sep 26, 2024
07301fe
change private_alloc to malloc to free memory by other thread
shparkcubrid Oct 24, 2024
0692623
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Oct 24, 2024
1be195e
fix to not add tran info for temporary file
shparkcubrid Oct 24, 2024
348138f
indent
shparkcubrid Oct 24, 2024
4fdd6d2
indent
shparkcubrid Oct 24, 2024
3367551
add check for splitted temp file and comment
shparkcubrid Oct 24, 2024
0c9d0ef
indent
shparkcubrid Oct 24, 2024
9e44f72
slip
shparkcubrid Oct 24, 2024
0ffb02c
add set_dirty for temp file
shparkcubrid Oct 24, 2024
e8ee99f
remove pgbuf_set_dirty temporarily
shparkcubrid Oct 25, 2024
9a89ef1
add sort_check_parallelism()
shparkcubrid Oct 28, 2024
6b98ae5
add start and end parallel
shparkcubrid Oct 29, 2024
763bb40
change private_alloc to malloc for freeing in main thread
shparkcubrid Oct 29, 2024
dfba094
slip
shparkcubrid Oct 29, 2024
eec95c9
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Oct 29, 2024
74d67dc
revert fix mode to PGBUF_LATCH_WRITE
shparkcubrid Oct 30, 2024
6a56eb0
fix memory leak
shparkcubrid Oct 30, 2024
c02ca4a
revert pgbuf_set_dirty
shparkcubrid Oct 30, 2024
1c95c40
revert set_dirty
shparkcubrid Oct 30, 2024
34292dc
add resource_tracker in parallel thread
shparkcubrid Nov 1, 2024
849eecd
revert private_alloc
shparkcubrid Nov 1, 2024
fb728f2
slip
shparkcubrid Nov 1, 2024
63b33b7
indent
shparkcubrid Nov 1, 2024
52f3ff3
enable pgbuf_set_dirty()
shparkcubrid Nov 1, 2024
42552ce
change pgbuf_set_dirty to qfile_set_dirty_page for memory buffer
shparkcubrid Nov 4, 2024
2f57e12
change qfile_set_dirty_page to qmgr_set_dirty_page
shparkcubrid Nov 4, 2024
cb4195e
revert pgbuf_unfix_all()
shparkcubrid Nov 6, 2024
a101b37
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Nov 12, 2024
c588ff6
add local mutex for temp file to avoid broken Linked list in parallel…
shparkcubrid Nov 19, 2024
4cc95ed
no busy wait. need to block and wake up.
shparkcubrid Nov 20, 2024
272ce1e
indent
shparkcubrid Nov 20, 2024
e9e5fa3
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Nov 20, 2024
d1fcff9
add merge routines upto 32 thread
shparkcubrid Dec 3, 2024
4f6a94c
add MAX_PARALLEL_THREAD system parameter and print execution time tem…
shparkcubrid Dec 5, 2024
afc5a44
indent
shparkcubrid Dec 5, 2024
4af0217
slip
shparkcubrid Dec 5, 2024
31610a5
slip
shparkcubrid Dec 5, 2024
6306774
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Dec 6, 2024
3d70364
slip
shparkcubrid Dec 9, 2024
c6af082
remove unnecessary var
shparkcubrid Dec 9, 2024
a2cccb2
indent
shparkcubrid Dec 9, 2024
fccfb9e
Merge remote-tracking branch 'remotemain/develop' into CBRD-25391
shparkcubrid Dec 9, 2024
3ba3d8a
Update src/base/system_parameter.c
shparkcubrid Dec 14, 2024
a56a11b
Update src/base/system_parameter.c
shparkcubrid Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/base/system_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ static const char sysprm_ha_conf_file_name[] = "cubrid_ha.conf";

#define PRM_NAME_CTE_MAX_RECURSIONS "cte_max_recursions"

#define PRM_NAME_MAX_PARALLEL_THREAD "max_parallel_thread"

#define PRM_NAME_DWB_SIZE "double_write_buffer_size"
#define PRM_NAME_DWB_BLOCKS "double_write_buffer_blocks"
#define PRM_NAME_ENABLE_DWB_FLUSH_THREAD "double_write_buffer_enable_flush_thread"
Expand Down Expand Up @@ -2159,6 +2161,12 @@ static int prm_cte_max_recursions_upper = 1000000;
static int prm_cte_max_recursions_lower = 2;
static unsigned int prm_cte_max_recursions_flag = 0;

int PRM_MAX_PARALLEL_THREAD = 1;
static int prm_max_parallel_thread_default = 1;
static int prm_max_parallel_thread_upper = 32;
static int prm_max_parallel_thread_lower = 1;
static unsigned int prm_max_parallel_thread_flag = 0;

bool PRM_JSON_LOG_ALLOCATIONS = false;
static bool prm_json_log_allocations_default = false;
static unsigned int prm_json_log_allocations_flag = 0;
Expand Down Expand Up @@ -6448,6 +6456,18 @@ SYSPRM_PARAM prm_Def[] = {
(void *) &prm_max_subquery_cache_size_lower,
(char *) NULL,
(DUP_PRM_FUNC) NULL,
(DUP_PRM_FUNC) NULL},
{PRM_ID_MAX_PARALLEL_THREAD,
PRM_NAME_MAX_PARALLEL_THREAD,
(PRM_FOR_SERVER | PRM_FOR_CLIENT | PRM_USER_CHANGE | PRM_FOR_SESSION | PRM_HIDDEN),
shparkcubrid marked this conversation as resolved.
Show resolved Hide resolved
PRM_INTEGER,
&prm_max_parallel_thread_flag,
(void *) &prm_max_parallel_thread_default,
(void *) &PRM_MAX_PARALLEL_THREAD,
(void *) &prm_max_parallel_thread_upper,
(void *) &prm_max_parallel_thread_lower,
(char *) NULL,
(DUP_PRM_FUNC) NULL,
(DUP_PRM_FUNC) NULL}
};

Expand Down
3 changes: 2 additions & 1 deletion src/base/system_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ enum param_id

PRM_ID_ENABLE_MEMORY_MONITORING,
PRM_ID_MAX_SUBQUERY_CACHE_SIZE,
PRM_ID_MAX_PARALLEL_THREAD,
/* change PRM_LAST_ID when adding new system parameters */
PRM_LAST_ID = PRM_ID_MAX_SUBQUERY_CACHE_SIZE
PRM_LAST_ID = PRM_ID_MAX_PARALLEL_THREAD
};
typedef enum param_id PARAM_ID;

Expand Down
24 changes: 21 additions & 3 deletions src/query/list_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ static void qfile_close_and_free_list_file (THREAD_ENTRY * thread_p, QFILE_LIST_
static QFILE_LIST_ID *qfile_union_list (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id1, QFILE_LIST_ID * list_id2,
int flag);

static SORT_STATUS qfile_get_next_sort_item (THREAD_ENTRY * thread_p, RECDES * recdes, void *arg);
static int qfile_put_next_sort_item (THREAD_ENTRY * thread_p, const RECDES * recdes, void *arg);
static SORT_STATUS qfile_get_next_sort_item (THREAD_ENTRY * thread_p, RECDES * recdes, void *arg);
static SORT_INFO *qfile_initialize_sort_info (SORT_INFO * info, QFILE_LIST_ID * listid, SORT_LIST * sort_list);
static void qfile_clear_sort_info (SORT_INFO * info);
static int qfile_copy_list_pages (THREAD_ENTRY * thread_p, VPID * old_first_vpidp, QMGR_TEMP_FILE * old_tfile_vfidp,
Expand Down Expand Up @@ -2230,7 +2230,7 @@ qfile_destroy_list (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p)
/* because qmgr_free_list_temp_file() destroy only FILE_TEMP file */
if (!VFID_ISNULL (&list_id_p->temp_vfid))
{
file_temp_retire (thread_p, &list_id_p->temp_vfid);
file_temp_retire (thread_p, &list_id_p->temp_vfid, false);
}
}

Expand Down Expand Up @@ -3983,6 +3983,9 @@ qfile_sort_list_with_func (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p, S
int sort_result, estimated_pages;
SORT_DUP_OPTION dup_option;

/* The result file must be closed for parallel processing. If not closed, Latch contention may occur. */
qfile_close_list (thread_p, list_id_p);

srlist_id = qfile_open_list (thread_p, &list_id_p->type_list, sort_list_p, list_id_p->query_id, flag, NULL);
if (srlist_id == NULL)
{
Expand All @@ -4005,6 +4008,7 @@ qfile_sort_list_with_func (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p, S

info.s_id = &s_scan_id;
info.output_file = srlist_id;
info.input_file = list_id_p;
info.extra_arg = extra_arg;

if (get_func == NULL)
Expand Down Expand Up @@ -4037,9 +4041,23 @@ qfile_sort_list_with_func (THREAD_ENTRY * thread_p, QFILE_LIST_ID * list_id_p, S

dup_option = ((option == Q_DISTINCT) ? SORT_ELIM_DUP : SORT_DUP);

#if !defined(NDEBUG)
TSC_TICKS start_tick, end_tick;
TSCTIMEVAL tv_diff;
struct timeval orderby_time;
tsc_getticks (&start_tick);
#endif

sort_result =
sort_listfile (thread_p, NULL_VOLID, estimated_pages, get_func, &info, put_func, &info, cmp_func, &info.key_info,
dup_option, limit, srlist_id->tfile_vfid->tde_encrypted);
dup_option, limit, srlist_id->tfile_vfid->tde_encrypted, SORT_ORDER_BY);

#if !defined(NDEBUG)
tsc_getticks (&end_tick);
tsc_elapsed_time_usec (&tv_diff, end_tick, start_tick);
TSC_ADD_TIMEVAL (orderby_time, tv_diff);
printf ("sort_listfile time: %d\n", TO_MSEC (orderby_time));
#endif

if (sort_result < 0)
{
Expand Down
1 change: 1 addition & 0 deletions src/query/list_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,5 @@ extern int qfile_get_list_cache_number_of_entries (int ht_no);
extern bool qfile_has_no_cache_entries ();



#endif /* _LIST_FILE_H_ */
7 changes: 4 additions & 3 deletions src/query/query_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -4695,7 +4695,7 @@ qexec_groupby (THREAD_ENTRY * thread_p, XASL_NODE * xasl, XASL_STATE * xasl_stat
/* sort and aggregate partial results */
if (sort_listfile (thread_p, NULL_VOLID, estimated_pages, &qexec_hash_gby_get_next, &gbstate,
&qexec_hash_gby_put_next, &gbstate, cmp_fn, &gbstate.agg_hash_context->sort_key, SORT_DUP,
NO_SORT_LIMIT, gbstate.output_file->tfile_vfid->tde_encrypted) != NO_ERROR)
NO_SORT_LIMIT, gbstate.output_file->tfile_vfid->tde_encrypted, SORT_GROUP_BY) != NO_ERROR)
{
GOTO_EXIT_ON_ERROR;
}
Expand Down Expand Up @@ -4776,7 +4776,7 @@ qexec_groupby (THREAD_ENTRY * thread_p, XASL_NODE * xasl, XASL_STATE * xasl_stat

if (sort_listfile (thread_p, NULL_VOLID, estimated_pages, &qexec_gby_get_next, &gbstate, &qexec_gby_put_next,
&gbstate, gbstate.cmp_fn, &gbstate.key_info, SORT_DUP, NO_SORT_LIMIT,
gbstate.output_file->tfile_vfid->tde_encrypted) != NO_ERROR)
gbstate.output_file->tfile_vfid->tde_encrypted, SORT_GROUP_BY) != NO_ERROR)
{
GOTO_EXIT_ON_ERROR;
}
Expand Down Expand Up @@ -22206,7 +22206,8 @@ qexec_execute_analytic (THREAD_ENTRY * thread_p, XASL_NODE * xasl, XASL_STATE *

if (sort_listfile (thread_p, NULL_VOLID, estimated_pages, &qexec_analytic_get_next, &analytic_state,
&qexec_analytic_put_next, &analytic_state, analytic_state.cmp_fn, &analytic_state.key_info,
SORT_DUP, NO_SORT_LIMIT, analytic_state.output_file->tfile_vfid->tde_encrypted) != NO_ERROR)
SORT_DUP, NO_SORT_LIMIT, analytic_state.output_file->tfile_vfid->tde_encrypted,
SORT_ANALYTIC) != NO_ERROR)
{
GOTO_EXIT_ON_ERROR;
}
Expand Down
12 changes: 6 additions & 6 deletions src/query/query_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,7 @@ qmgr_get_new_page (THREAD_ENTRY * thread_p, VPID * vpid_p, QMGR_TEMP_FILE * tfil
if (VFID_ISNULL (&tfile_vfid_p->temp_vfid))
{
TDE_ALGORITHM tde_algo = TDE_ALGORITHM_NONE;
if (file_create_temp (thread_p, 1, &tfile_vfid_p->temp_vfid) != NO_ERROR)
if (file_create_temp (thread_p, 1, &tfile_vfid_p->temp_vfid, false) != NO_ERROR)
{
ASSERT_ERROR ();
return NULL;
Expand All @@ -2607,7 +2607,7 @@ qmgr_get_new_page (THREAD_ENTRY * thread_p, VPID * vpid_p, QMGR_TEMP_FILE * tfil
if (file_apply_tde_algorithm (thread_p, &tfile_vfid_p->temp_vfid, tde_algo) != NO_ERROR)
{
ASSERT_ERROR ();
file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid);
file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid, false);
VFID_SET_NULL (&tfile_vfid_p->temp_vfid);
return NULL;
}
Expand Down Expand Up @@ -2871,7 +2871,7 @@ qmgr_create_result_file (THREAD_ENTRY * thread_p, QUERY_ID query_id)
{
/* query entry is not found */
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_QPROC_UNKNOWN_QUERYID, 1, query_id);
file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid);
file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid, false);
free_and_init (tfile_vfid_p);
return NULL;
}
Expand All @@ -2884,7 +2884,7 @@ qmgr_create_result_file (THREAD_ENTRY * thread_p, QUERY_ID query_id)

if (file_apply_tde_algorithm (thread_p, &tfile_vfid_p->temp_vfid, tde_algo) != NO_ERROR)
{
file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid);
file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid, false);
free_and_init (tfile_vfid_p);
return NULL;
}
Expand Down Expand Up @@ -2954,7 +2954,7 @@ qmgr_free_temp_file_list (THREAD_ENTRY * thread_p, QMGR_TEMP_FILE * tfile_vfid_p
}
else
{
fd_ret = file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid);
fd_ret = file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid, false);
if (fd_ret != NO_ERROR)
{
/* set error but continue with the destroy process */
Expand Down Expand Up @@ -3095,7 +3095,7 @@ qmgr_free_list_temp_file (THREAD_ENTRY * thread_p, QUERY_ID query_id, QMGR_TEMP_
rc = ER_FAILED;
}
}
else if (file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid) != NO_ERROR)
else if (file_temp_retire (thread_p, &tfile_vfid_p->temp_vfid, false) != NO_ERROR)
{
/* stop; return error */
rc = ER_FAILED;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/btree_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -3217,7 +3217,7 @@ btree_index_sort (THREAD_ENTRY * thread_p, SORT_ARGS * sort_args, SORT_PUT_FUNC

return sort_listfile (thread_p, sort_args->hfids[0].vfid.volid, 0 /* TODO - support parallelism */ ,
&btree_sort_get_next, sort_args, out_func, out_args, compare_driver, sort_args, SORT_DUP,
NO_SORT_LIMIT, includes_tde_class);
NO_SORT_LIMIT, includes_tde_class, SORT_INDEX_LEAF);
}

/*
Expand Down
Loading
Loading