CUBRID Engine
latest
Main Page
Namespaces
Classes
Files
File List
File Members
external_sort.h
Go to the documentation of this file.
1
/*
2
* Copyright 2008 Search Solution Corporation
3
* Copyright 2016 CUBRID Corporation
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*/
18
19
20
/*
21
* external_sort.h - External sorting module
22
*/
23
24
#ifndef _EXTERNAL_SORT_H_
25
#define _EXTERNAL_SORT_H_
26
27
#ident "$Id$"
28
29
#if !defined (SERVER_MODE) && !defined (SA_MODE)
30
#error Belongs to server module
31
#endif
/* !defined (SERVER_MODE) && !defined (SA_MODE) */
32
33
#include "
error_manager.h
"
34
#include "
query_list.h
"
35
#include "
storage_common.h
"
36
#include "
thread_compat.hpp
"
37
38
#define SORT_PUT_STOP 2
39
40
#define NO_SORT_LIMIT (-1)
41
42
#define SORT_RECORD_LENGTH_SIZE (sizeof(INT64))
/* for 8byte align */
43
#define SORT_RECORD_LENGTH(item_p) (*((int *) ((item_p) - SORT_RECORD_LENGTH_SIZE)))
44
45
typedef
enum
46
{
47
SORT_REC_DOESNT_FIT
,
48
SORT_SUCCESS
,
49
SORT_NOMORE_RECS
,
50
SORT_ERROR_OCCURRED
51
}
SORT_STATUS
;
52
53
typedef
enum
54
{
55
SORT_ELIM_DUP
,
/* eliminate duplicate */
56
SORT_DUP
/* allow duplicate */
57
}
SORT_DUP_OPTION
;
58
59
typedef
SORT_STATUS
SORT_GET_FUNC
(
THREAD_ENTRY
* thread_p,
RECDES
*,
void
*);
60
typedef
int
SORT_PUT_FUNC
(
THREAD_ENTRY
* thread_p,
const
RECDES
*,
void
*);
61
typedef
int
SORT_CMP_FUNC
(
const
void
*,
const
void
*,
void
*);
62
63
typedef
struct
SORT_REC
SORT_REC
;
64
typedef
struct
SUBKEY_INFO
SUBKEY_INFO
;
65
typedef
struct
SORTKEY_INFO
SORTKEY_INFO
;
66
typedef
struct
SORT_INFO
SORT_INFO
;
67
68
struct
SORT_REC
69
{
70
SORT_REC
*
next
;
/* forward link for duplicate sort_key value */
71
union
72
{
73
/* Bread crumbs back to the original tuple, so that we can go straight there after the keys have been sorted. */
74
struct
75
{
76
INT32
pageid
;
/* Page identifier */
77
INT16
volid
;
/* Volume identifier */
78
INT16
offset
;
/* offset in page */
79
char
body
[1];
/* sort_key body start position */
80
}
original
;
81
82
/*
83
* The offset vector. A value of zero for an entry means that the
84
* corresponding column is null, and that there are no data bytes for
85
* the column. A non-zero entry is interpreted as the offset from
86
* the *start* of the SORT_REC to the data bytes for that column.
87
*/
88
int
offset
[1];
89
}
s
;
90
};
91
92
struct
SUBKEY_INFO
93
{
94
/* The actual column number in the list file tuple. */
95
int
col
;
96
97
98
int
permuted_col
;
99
100
TP_DOMAIN
*
col_dom
;
101
102
TP_DOMAIN
*
cmp_dom
;
/* for median sorting string in different domain */
103
104
// signature should match pr_type::data_cmpdisk_function_type
105
// todo - use a function type for both sort_f and pr_type::data_cmpdisk_function_type
106
DB_VALUE_COMPARE_RESULT
(*sort_f) (
void
*tplp1,
void
*tplp2,
TP_DOMAIN
* dom,
int
do_coercion,
int
total_order,
107
int
*start_col);
108
109
/*
110
* Non-zero iff the sort on this column is descending. Factoring
111
* this decision out of the actual sort function allows to use only
112
* one of those guys, at no particularly great cost in performance,
113
* and a big win in maintainability.
114
*/
115
int
is_desc
;
116
117
int
is_nulls_first
;
118
119
bool
use_cmp_dom
;
/* when true, use cmp_dom to make comparing */
120
};
121
122
struct
SORTKEY_INFO
123
{
124
int
nkeys
;
/* The number of columns in use today. */
125
int
use_original
;
/* False iff the sort keys consist of all of the input record fields, i.e., if we'll
126
* reconstruct the input records from the keys rather than look them up again in the
127
* original file. */
128
SUBKEY_INFO
*
key
;
/* Points to `default_keys' if `nkeys' <= 8; otherwise it points to malloc'ed space. */
129
SUBKEY_INFO
default_keys[8];
/* Default storage; this ought to work for most cases. */
130
int
error
;
/* median domain convert errors */
131
};
132
133
struct
SORT_INFO
134
{
135
SORTKEY_INFO
key_info
;
/* All of the interesting key information. */
136
QFILE_SORT_SCAN_ID
*
s_id
;
/* A SCAN_ID for the input list file. This is stateful, and records the current
137
* location of the scan between calls to ls_sort_get_next(). */
138
QFILE_LIST_ID
*
output_file
;
/* The name of the output file. This is where ls_sort_put_next_*() deposits its stuff.
139
*/
140
RECDES
output_recdes
;
/* A working buffer for output of tuples; used only when we're using
141
* ls_sort_put_next_short() as the output function. */
142
void
*
extra_arg
;
/* extra information supplied by the caller */
143
};
144
145
extern
int
sort_listfile
(
THREAD_ENTRY
* thread_p, INT16
volid
,
int
est_inp_pg_cnt,
SORT_GET_FUNC
* get_fn,
146
void
*get_arg,
SORT_PUT_FUNC
* put_fn,
void
*put_arg,
SORT_CMP_FUNC
* cmp_fn,
void
*cmp_arg,
147
SORT_DUP_OPTION
option
,
int
limit,
bool
includes_tde_class);
148
149
#endif
/* _EXTERNAL_SORT_H_ */
SUBKEY_INFO::permuted_col
int permuted_col
Definition:
external_sort.h:98
SORT_REC::volid
INT16 volid
Definition:
external_sort.h:77
SORT_REC::s
union SORT_REC::@159 s
thread_compat.hpp
SORTKEY_INFO::nkeys
int nkeys
Definition:
external_sort.h:124
SORT_REC
Definition:
external_sort.h:68
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)
Definition:
external_sort.c:1345
SORT_INFO::s_id
QFILE_SORT_SCAN_ID * s_id
Definition:
external_sort.h:136
SORT_PUT_FUNC
int SORT_PUT_FUNC(THREAD_ENTRY *thread_p, const RECDES *, void *)
Definition:
external_sort.h:60
SORT_SUCCESS
Definition:
external_sort.h:48
SORT_INFO::output_file
QFILE_LIST_ID * output_file
Definition:
external_sort.h:138
SORT_ELIM_DUP
Definition:
external_sort.h:55
SORT_INFO::extra_arg
void * extra_arg
Definition:
external_sort.h:142
SUBKEY_INFO::is_nulls_first
int is_nulls_first
Definition:
external_sort.h:117
SORT_REC::offset
INT16 offset
Definition:
external_sort.h:78
storage_common.h
SORT_ERROR_OCCURRED
Definition:
external_sort.h:50
SUBKEY_INFO::cmp_dom
TP_DOMAIN * cmp_dom
Definition:
external_sort.h:102
SORT_REC::body
char body[1]
Definition:
external_sort.h:79
qfile_sort_scan_id
Definition:
query_list.h:539
THREAD_ENTRY
void THREAD_ENTRY
Definition:
thread_compat.hpp:43
SORT_REC_DOESNT_FIT
Definition:
external_sort.h:47
SORT_INFO::key_info
SORTKEY_INFO key_info
Definition:
external_sort.h:135
SUBKEY_INFO::col
int col
Definition:
external_sort.h:95
option
Definition:
cubrid_getopt.h:53
recdes
Definition:
storage_common.h:216
query_list.h
SORTKEY_INFO::error
int error
Definition:
external_sort.h:130
SUBKEY_INFO::col_dom
TP_DOMAIN * col_dom
Definition:
external_sort.h:100
tp_domain
Definition:
object_domain.h:72
qfile_list_id
Definition:
query_list.h:426
SORT_REC::next
SORT_REC * next
Definition:
external_sort.h:70
SORT_STATUS
SORT_STATUS
Definition:
external_sort.h:45
SORTKEY_INFO::use_original
int use_original
Definition:
external_sort.h:125
SORT_REC::original
struct SORT_REC::@159::@160 original
SUBKEY_INFO::is_desc
int is_desc
Definition:
external_sort.h:115
SORT_INFO
Definition:
external_sort.h:133
SORT_DUP_OPTION
SORT_DUP_OPTION
Definition:
external_sort.h:53
SORT_INFO::output_recdes
RECDES output_recdes
Definition:
external_sort.h:140
error_manager.h
SORTKEY_INFO::key
SUBKEY_INFO * key
Definition:
external_sort.h:128
SUBKEY_INFO::use_cmp_dom
bool use_cmp_dom
Definition:
external_sort.h:119
SUBKEY_INFO
Definition:
external_sort.h:92
SORTKEY_INFO
Definition:
external_sort.h:122
DB_VALUE_COMPARE_RESULT
DB_VALUE_COMPARE_RESULT
Definition:
dbtype_def.h:199
SORT_CMP_FUNC
int SORT_CMP_FUNC(const void *, const void *, void *)
Definition:
external_sort.h:61
SORT_DUP
Definition:
external_sort.h:56
SORT_REC::pageid
INT32 pageid
Definition:
external_sort.h:76
SORT_GET_FUNC
SORT_STATUS SORT_GET_FUNC(THREAD_ENTRY *thread_p, RECDES *, void *)
Definition:
external_sort.h:59
SORT_NOMORE_RECS
Definition:
external_sort.h:49
src
storage
external_sort.h
Generated by
1.8.11