Skip to content

File external_sort.c

FileList > cubrid > src > storage > external_sort.c

Go to the source code of this file

  • #include "config.h"
  • #include <stdio.h>
  • #include <string.h>
  • #include <stddef.h>
  • #include <stdlib.h>
  • #include <math.h>
  • #include "error_manager.h"
  • #include "system_parameter.h"
  • #include "memory_alloc.h"
  • #include "external_sort.h"
  • #include "file_manager.h"
  • #include "page_buffer.h"
  • #include "log_manager.h"
  • #include "disk_manager.h"
  • #include "slotted_page.h"
  • #include "overflow_file.h"
  • #include "boot_sr.h"
  • #include "connection_error.h"
  • #include "server_support.h"
  • #include "thread_entry_task.hpp"
  • #include "thread_manager.hpp"
  • #include "list_file.h"
  • #include "query_manager.h"
  • #include "object_representation.h"
  • #include "px_worker_manager.hpp"
  • #include "px_callable_task.hpp"
  • #include "px_parallel.hpp"
  • #include "px_sort.h"
  • #include "btree_load.h"
  • #include "px_ftab_set.hpp"
  • #include <functional>
  • #include "memory_wrapper.hpp"

Classes

Type Name
struct file_contents
struct run_struct
struct slot
struct slotted_pheader
struct sort_param
struct sort_rec_list
struct sort_stack
struct srun
struct vol_info
struct vol_list

Public Types

Type Name
typedef struct file_contents FILE_CONTENTS
typedef void FIND_RUN_FN
typedef void MERGE_RUN_FN
typedef struct run_struct RUN
typedef struct slot SLOT
typedef struct slotted_pheader SLOTTED_PAGE_HEADER
typedef struct sort_param SORT_PARAM
typedef struct sort_rec_list SORT_REC_LIST
typedef struct sort_stack SORT_STACK
typedef struct srun SRUN
typedef struct vol_info VOL_INFO
typedef struct vol_list VOL_LIST

Public Functions

Type Name
int sort_check_parallelism (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param)
int sort_copy_sort_param (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param, int parallel_num)
int sort_end_parallelism (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param)
int sort_listfile (THREAD_ENTRY * thread_p, INT16 volid, int est_inp_pg_cnt, SORT_GET_FUNC * get_fn, void * get_arg, SORT_PUT_FUNC * put_fn, void * put_arg, SORT_CMP_FUNC * cmp_fn, void * cmp_arg, SORT_DUP_OPTION option, int limit, bool includes_tde_class, SORT_PARALLEL_TYPE parallel_type)
void sort_listfile_execute (cubthread::entry & thread_ref, SORT_PARAM * sort_param)
int sort_merge_nruns (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param)
void sort_merge_nruns_parallel (cubthread::entry & thread_ref, SORT_PARAM * sort_param)
int sort_merge_run_for_parallel (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param, int parallel_num)
void sort_put_result_for_parallel (cubthread::entry & thread_ref, SORT_PARAM * sort_param)
int sort_put_result_from_tmpfile (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param, int start_pagenum)
int sort_split_input_temp_file (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param, int parallel_num)
void sort_split_last_run (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param, int parallel_num)
int sort_start_parallelism (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param)

Public Static Functions

Type Name
int sort_add_new_file (THREAD_ENTRY * thread_p, VFID * vfid, int file_pg_cnt_est, bool force_alloc, bool tde_encrypted)
void sort_append (const void * pk0, const void * pk1)
int sort_checkalloc_numpages_of_outfiles (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param)
int sort_exphase_merge (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param)
int sort_exphase_merge_elim_dup (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param)
int sort_find_inbuf_size (int tot_buffers, int in_sections)
int sort_get_avg_numpages_of_nonempty_tmpfile (SORT_PARAM * sort_param)
int sort_get_num_file_contents (FILE_CONTENTS * file_contents)
int sort_get_num_half_tmpfiles (int tot_buffers, int input_pages)
int sort_get_numpages_of_active_infiles (const SORT_PARAM * sort_param)
int sort_inphase_sort (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param, SORT_GET_FUNC * get_next, void * arguments, unsigned int * total_numrecs)
int sort_listfile_internal (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param)
int sort_merge_run_for_parallel_index_leaf_build (THREAD_ENTRY * thread_p, SORT_PARAM * px_sort_param, SORT_PARAM * sort_param, int parallel_num)
void sort_print_file_contents (const FILE_CONTENTS * file_contents)
int sort_read_area (THREAD_ENTRY * thread_p, VFID * vfid, int first_page, INT32 num_pages, char * area_start)
char * sort_retrieve_longrec (THREAD_ENTRY * thread_p, RECDES * address, RECDES * memory)
void sort_return_used_resources (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param, PARALLEL_TYPE parallel_type)
int sort_run_add_new (FILE_CONTENTS * file_contents, int num_pages)
void sort_run_find (char ** source, long * top, SORT_STACK * st_p, long limit, SORT_CMP_FUNC * compare, void * comp_arg, SORT_DUP_OPTION option)
void sort_run_flip (char ** start, char ** stop)
int sort_run_flush (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param, int out_curfile, int * cur_page, char * output_buffer, char ** index_area, int numrecs, int rec_type)
void sort_run_merge (char ** low, char ** high, SORT_STACK * st_p, SORT_CMP_FUNC * compare, void * comp_arg, SORT_DUP_OPTION option)
void sort_run_remove_first (FILE_CONTENTS * file_contents)
char ** sort_run_sort (THREAD_ENTRY * thread_p, SORT_PARAM * sort_param, char ** base, long limit, long sort_numrecs, char ** otherbase, long * srun_limit)
int sort_spage_compact (PAGE_PTR pgptr)
void sort_spage_dump (PAGE_PTR pgptr, int rec_p)
void sort_spage_dump_hdr (SLOTTED_PAGE_HEADER * sphdr)
INT16 sort_spage_dump_sptr (SLOT * sptr, INT16 nslots, INT16 alignment)
INT16 sort_spage_find_free (PAGE_PTR pgptr, SLOT ** sptr, INT16 length, INT16 type, INT16 * space)
INT16 sort_spage_get_numrecs (PAGE_PTR pgptr)
SCAN_CODE sort_spage_get_record (PAGE_PTR pgptr, INT16 slotid, RECDES * recdes, bool peek_p)
void sort_spage_initialize (PAGE_PTR pgptr, INT16 slots_type, INT16 alignment)
INT16 sort_spage_insert (PAGE_PTR pgptr, RECDES * recdes)
int sort_spage_offsetcmp (const void * s1, const void * s2)
int sort_validate (char ** vector, long size, SORT_CMP_FUNC * compare, void * comp_arg)
int sort_write_area (THREAD_ENTRY * thread_p, VFID * vfid, int first_page, INT32 num_pages, char * area_start, bool tde_encrypted)

Macros

Type Name
define SORT_CHECK_DUPLICATE (a, b) /* multi line expression */
define SORT_EXPAND_DYN_ARRAY_RATIO 1.5
define SORT_INITIAL_DYN_ARRAY_SIZE 30
define SORT_MAXREC_LENGTH (([**ssize\_t**](broker__monitor_8c.md#function-timeout))([**DB\_PAGESIZE**](storage__common_8h.md#define-db_pagesize) - [**sizeof**](broker__monitor_8c.md#function-timeout)([**SLOTTED\_PAGE\_HEADER**](external__sort_8c.md#typedef-slotted_page_header)) - [**sizeof**](broker__monitor_8c.md#function-timeout)([**SLOT**](external__sort_8c.md#typedef-slot))))
define SORT_MAX_HALF_FILES 4
define SORT_MAX_TOT_FILES [**SORT\_MAX\_HALF\_FILES**](external__sort_8c.md#define-sort_max_half_files) \* 2
define SORT_MIN_HALF_FILES 2
define SORT_MULTIPAGE_FILE_SIZE_ESTIMATE 20
define SORT_SWAP_PTR (a, b) { [**char**](broker__monitor_8c.md#function-timeout) \*\*temp; temp = [**a**](broker__monitor_8c.md#function-timeout); [**a**](broker__monitor_8c.md#function-timeout) = b; b = temp; }

Public Types Documentation

typedef FILE_CONTENTS

typedef struct file_contents FILE_CONTENTS;

typedef FIND_RUN_FN

typedef void FIND_RUN_FN(char **, long *, SORT_STACK *, long, SORT_CMP_FUNC *, void *);

typedef MERGE_RUN_FN

typedef void MERGE_RUN_FN(char **, char **, SORT_STACK *, SORT_CMP_FUNC *, void *);

typedef RUN

typedef struct run_struct RUN;

typedef SLOT

typedef struct slot SLOT;

typedef SLOTTED_PAGE_HEADER

typedef struct slotted_pheader SLOTTED_PAGE_HEADER;

typedef SORT_PARAM

typedef struct sort_param SORT_PARAM;

typedef SORT_REC_LIST

typedef struct sort_rec_list SORT_REC_LIST;

typedef SORT_STACK

typedef struct sort_stack SORT_STACK;

typedef SRUN

typedef struct srun SRUN;

typedef VOL_INFO

typedef struct vol_info VOL_INFO;

typedef VOL_LIST

typedef struct vol_list VOL_LIST;

Public Functions Documentation

function sort_check_parallelism

int sort_check_parallelism (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param
) 

function sort_copy_sort_param

int sort_copy_sort_param (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param,
    int parallel_num
) 

function sort_end_parallelism

int sort_end_parallelism (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param
) 

function sort_listfile

int sort_listfile (
    THREAD_ENTRY * thread_p,
    INT16 volid,
    int est_inp_pg_cnt,
    SORT_GET_FUNC * get_fn,
    void * get_arg,
    SORT_PUT_FUNC * put_fn,
    void * put_arg,
    SORT_CMP_FUNC * cmp_fn,
    void * cmp_arg,
    SORT_DUP_OPTION option,
    int limit,
    bool includes_tde_class,
    SORT_PARALLEL_TYPE parallel_type
) 

function sort_listfile_execute

void sort_listfile_execute (
    cubthread::entry & thread_ref,
    SORT_PARAM * sort_param
) 

function sort_merge_nruns

int sort_merge_nruns (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param
) 

function sort_merge_nruns_parallel

void sort_merge_nruns_parallel (
    cubthread::entry & thread_ref,
    SORT_PARAM * sort_param
) 

function sort_merge_run_for_parallel

int sort_merge_run_for_parallel (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param,
    int parallel_num
) 

function sort_put_result_for_parallel

void sort_put_result_for_parallel (
    cubthread::entry & thread_ref,
    SORT_PARAM * sort_param
) 

function sort_put_result_from_tmpfile

int sort_put_result_from_tmpfile (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param,
    int start_pagenum
) 

function sort_split_input_temp_file

int sort_split_input_temp_file (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param,
    int parallel_num
) 

function sort_split_last_run

void sort_split_last_run (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param,
    int parallel_num
) 

function sort_start_parallelism

int sort_start_parallelism (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param
) 

Public Static Functions Documentation

function sort_add_new_file

static int sort_add_new_file (
    THREAD_ENTRY * thread_p,
    VFID * vfid,
    int file_pg_cnt_est,
    bool force_alloc,
    bool tde_encrypted
) 

function sort_append

static void sort_append (
    const  void * pk0,
    const  void * pk1
) 

function sort_checkalloc_numpages_of_outfiles

static int sort_checkalloc_numpages_of_outfiles (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param
) 

function sort_exphase_merge

static int sort_exphase_merge (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param
) 

function sort_exphase_merge_elim_dup

static int sort_exphase_merge_elim_dup (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param
) 

function sort_find_inbuf_size

static int sort_find_inbuf_size (
    int tot_buffers,
    int in_sections
) 

function sort_get_avg_numpages_of_nonempty_tmpfile

static int sort_get_avg_numpages_of_nonempty_tmpfile (
    SORT_PARAM * sort_param
) 

function sort_get_num_file_contents

static int sort_get_num_file_contents (
    FILE_CONTENTS * file_contents
) 

function sort_get_num_half_tmpfiles

static int sort_get_num_half_tmpfiles (
    int tot_buffers,
    int input_pages
) 

function sort_get_numpages_of_active_infiles

static int sort_get_numpages_of_active_infiles (
    const  SORT_PARAM * sort_param
) 

function sort_inphase_sort

static int sort_inphase_sort (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param,
    SORT_GET_FUNC * get_next,
    void * arguments,
    unsigned  int * total_numrecs
) 

function sort_listfile_internal

static int sort_listfile_internal (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param
) 

function sort_merge_run_for_parallel_index_leaf_build

static int sort_merge_run_for_parallel_index_leaf_build (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * px_sort_param,
    SORT_PARAM * sort_param,
    int parallel_num
) 

function sort_print_file_contents

static void sort_print_file_contents (
    const  FILE_CONTENTS * file_contents
) 

function sort_read_area

static int sort_read_area (
    THREAD_ENTRY * thread_p,
    VFID * vfid,
    int first_page,
    INT32 num_pages,
    char * area_start
) 

function sort_retrieve_longrec

static char * sort_retrieve_longrec (
    THREAD_ENTRY * thread_p,
    RECDES * address,
    RECDES * memory
) 

function sort_return_used_resources

static void sort_return_used_resources (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param,
    PARALLEL_TYPE parallel_type
) 

function sort_run_add_new

static int sort_run_add_new (
    FILE_CONTENTS * file_contents,
    int num_pages
) 

function sort_run_find

static void sort_run_find (
    char ** source,
    long * top,
    SORT_STACK * st_p,
    long limit,
    SORT_CMP_FUNC * compare,
    void * comp_arg,
    SORT_DUP_OPTION option
) 

function sort_run_flip

static void sort_run_flip (
    char ** start,
    char ** stop
) 

function sort_run_flush

static int sort_run_flush (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param,
    int out_curfile,
    int * cur_page,
    char * output_buffer,
    char ** index_area,
    int numrecs,
    int rec_type
) 

function sort_run_merge

static void sort_run_merge (
    char ** low,
    char ** high,
    SORT_STACK * st_p,
    SORT_CMP_FUNC * compare,
    void * comp_arg,
    SORT_DUP_OPTION option
) 

function sort_run_remove_first

static void sort_run_remove_first (
    FILE_CONTENTS * file_contents
) 

function sort_run_sort

static char ** sort_run_sort (
    THREAD_ENTRY * thread_p,
    SORT_PARAM * sort_param,
    char ** base,
    long limit,
    long sort_numrecs,
    char ** otherbase,
    long * srun_limit
) 

function sort_spage_compact

static int sort_spage_compact (
    PAGE_PTR pgptr
) 

function sort_spage_dump

static void sort_spage_dump (
    PAGE_PTR pgptr,
    int rec_p
) 

function sort_spage_dump_hdr

static void sort_spage_dump_hdr (
    SLOTTED_PAGE_HEADER * sphdr
) 

function sort_spage_dump_sptr

static INT16 sort_spage_dump_sptr (
    SLOT * sptr,
    INT16 nslots,
    INT16 alignment
) 

function sort_spage_find_free

static INT16 sort_spage_find_free (
    PAGE_PTR pgptr,
    SLOT ** sptr,
    INT16 length,
    INT16 type,
    INT16 * space
) 

function sort_spage_get_numrecs

static INT16 sort_spage_get_numrecs (
    PAGE_PTR pgptr
) 

function sort_spage_get_record

static SCAN_CODE sort_spage_get_record (
    PAGE_PTR pgptr,
    INT16 slotid,
    RECDES * recdes,
    bool peek_p
) 

function sort_spage_initialize

static void sort_spage_initialize (
    PAGE_PTR pgptr,
    INT16 slots_type,
    INT16 alignment
) 

function sort_spage_insert

static INT16 sort_spage_insert (
    PAGE_PTR pgptr,
    RECDES * recdes
) 

function sort_spage_offsetcmp

static int sort_spage_offsetcmp (
    const  void * s1,
    const  void * s2
) 

function sort_validate

static int sort_validate (
    char ** vector,
    long size,
    SORT_CMP_FUNC * compare,
    void * comp_arg
) 

function sort_write_area

static int sort_write_area (
    THREAD_ENTRY * thread_p,
    VFID * vfid,
    int first_page,
    INT32 num_pages,
    char * area_start,
    bool tde_encrypted
) 

Macro Definition Documentation

define SORT_CHECK_DUPLICATE

#define SORT_CHECK_DUPLICATE (
    a,
    b
) `/* multi line expression */`

define SORT_EXPAND_DYN_ARRAY_RATIO

#define SORT_EXPAND_DYN_ARRAY_RATIO `1.5`

define SORT_INITIAL_DYN_ARRAY_SIZE

#define SORT_INITIAL_DYN_ARRAY_SIZE `30`

define SORT_MAXREC_LENGTH

#define SORT_MAXREC_LENGTH `(( ssize_t )( DB_PAGESIZE - sizeof ( SLOTTED_PAGE_HEADER ) - sizeof ( SLOT )))`

define SORT_MAX_HALF_FILES

#define SORT_MAX_HALF_FILES `4`

define SORT_MAX_TOT_FILES

#define SORT_MAX_TOT_FILES `SORT_MAX_HALF_FILES * 2`

define SORT_MIN_HALF_FILES

#define SORT_MIN_HALF_FILES `2`

define SORT_MULTIPAGE_FILE_SIZE_ESTIMATE

#define SORT_MULTIPAGE_FILE_SIZE_ESTIMATE `20`

define SORT_SWAP_PTR

#define SORT_SWAP_PTR (
    a,
    b
) `{ char **temp; temp = a ; a = b; b = temp; }`


The documentation for this class was generated from the following file cubrid/src/storage/external_sort.c