Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
d7447842
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d7447842
编写于
9月 10, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-1411]
上级
a30dd562
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
46 deletion
+58
-46
src/common/src/ttypes.c
src/common/src/ttypes.c
+3
-6
src/inc/taosdef.h
src/inc/taosdef.h
+1
-1
src/query/src/qExtbuffer.c
src/query/src/qExtbuffer.c
+54
-39
未找到文件。
src/common/src/ttypes.c
浏览文件 @
d7447842
...
@@ -540,9 +540,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
...
@@ -540,9 +540,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
}
}
}
}
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
)
{
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
)
{
char
tmpBuf
[
4096
]
=
{
0
};
switch
(
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_INT
:
{
case
TSDB_DATA_TYPE_INT
:
{
SWAP
(
*
(
int32_t
*
)(
pLeft
),
*
(
int32_t
*
)(
pRight
),
int32_t
);
SWAP
(
*
(
int32_t
*
)(
pLeft
),
*
(
int32_t
*
)(
pRight
),
int32_t
);
...
@@ -575,10 +573,9 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size) {
...
@@ -575,10 +573,9 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size) {
}
}
default:
{
default:
{
assert
(
size
<=
4096
);
memcpy
(
buf
,
pLeft
,
size
);
memcpy
(
tmpBuf
,
pLeft
,
size
);
memcpy
(
pLeft
,
pRight
,
size
);
memcpy
(
pLeft
,
pRight
,
size
);
memcpy
(
pRight
,
tmpB
uf
,
size
);
memcpy
(
pRight
,
b
uf
,
size
);
break
;
break
;
}
}
}
}
...
...
src/inc/taosdef.h
浏览文件 @
d7447842
...
@@ -198,7 +198,7 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems);
...
@@ -198,7 +198,7 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems);
void
*
getNullValue
(
int32_t
type
);
void
*
getNullValue
(
int32_t
type
);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
);
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
);
// TODO: check if below is necessary
// TODO: check if below is necessary
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_INVALID 0
...
...
src/query/src/qExtbuffer.c
浏览文件 @
d7447842
...
@@ -502,22 +502,22 @@ FORCE_INLINE int32_t compare_sd(tOrderDescriptor *pDescriptor, int32_t numOfRows
...
@@ -502,22 +502,22 @@ FORCE_INLINE int32_t compare_sd(tOrderDescriptor *pDescriptor, int32_t numOfRows
return
compare_d
(
pDescriptor
,
numOfRows
,
idx1
,
data
,
numOfRows
,
idx2
,
data
);
return
compare_d
(
pDescriptor
,
numOfRows
,
idx1
,
data
,
numOfRows
,
idx2
,
data
);
}
}
static
void
swap
(
SColumnModel
*
pColumnModel
,
int32_t
count
,
int32_t
s1
,
char
*
data1
,
int32_t
s2
)
{
static
void
swap
(
SColumnModel
*
pColumnModel
,
int32_t
count
,
int32_t
s1
,
char
*
data1
,
int32_t
s2
,
void
*
buf
)
{
for
(
int32_t
i
=
0
;
i
<
pColumnModel
->
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pColumnModel
->
numOfCols
;
++
i
)
{
void
*
first
=
COLMODEL_GET_VAL
(
data1
,
pColumnModel
,
count
,
s1
,
i
);
void
*
first
=
COLMODEL_GET_VAL
(
data1
,
pColumnModel
,
count
,
s1
,
i
);
void
*
second
=
COLMODEL_GET_VAL
(
data1
,
pColumnModel
,
count
,
s2
,
i
);
void
*
second
=
COLMODEL_GET_VAL
(
data1
,
pColumnModel
,
count
,
s2
,
i
);
SSchema
*
pSchema
=
&
pColumnModel
->
pFields
[
i
].
field
;
SSchema
*
pSchema
=
&
pColumnModel
->
pFields
[
i
].
field
;
tsDataSwap
(
first
,
second
,
pSchema
->
type
,
pSchema
->
bytes
);
tsDataSwap
(
first
,
second
,
pSchema
->
type
,
pSchema
->
bytes
,
buf
);
}
}
}
}
static
void
tColDataInsertSort
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
static
void
tColDataInsertSort
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
__col_compar_fn_t
compareFn
)
{
__col_compar_fn_t
compareFn
,
void
*
buf
)
{
for
(
int32_t
i
=
start
+
1
;
i
<=
end
;
++
i
)
{
for
(
int32_t
i
=
start
+
1
;
i
<=
end
;
++
i
)
{
for
(
int32_t
j
=
i
;
j
>
start
;
--
j
)
{
for
(
int32_t
j
=
i
;
j
>
start
;
--
j
)
{
if
(
compareFn
(
pDescriptor
,
numOfRows
,
j
,
j
-
1
,
data
)
==
-
1
)
{
if
(
compareFn
(
pDescriptor
,
numOfRows
,
j
,
j
-
1
,
data
)
==
-
1
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
j
-
1
,
data
,
j
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
j
-
1
,
data
,
j
,
buf
);
}
else
{
}
else
{
break
;
break
;
}
}
...
@@ -553,7 +553,7 @@ static void UNUSED_FUNC tSortDataPrint(int32_t type, char *prefix, char *startx,
...
@@ -553,7 +553,7 @@ static void UNUSED_FUNC tSortDataPrint(int32_t type, char *prefix, char *startx,
}
}
static
void
median
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
static
void
median
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
__col_compar_fn_t
compareFn
)
{
__col_compar_fn_t
compareFn
,
void
*
buf
)
{
int32_t
midIdx
=
((
end
-
start
)
>>
1
)
+
start
;
int32_t
midIdx
=
((
end
-
start
)
>>
1
)
+
start
;
#if defined(_DEBUG_VIEW)
#if defined(_DEBUG_VIEW)
...
@@ -567,15 +567,16 @@ static void median(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
...
@@ -567,15 +567,16 @@ static void median(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
tSortDataPrint
(
pDescriptor
->
pColumnModel
->
pFields
[
colIdx
].
field
.
type
,
"before"
,
startx
,
midx
,
endx
);
tSortDataPrint
(
pDescriptor
->
pColumnModel
->
pFields
[
colIdx
].
field
.
type
,
"before"
,
startx
,
midx
,
endx
);
#endif
#endif
SColumnModel
*
pModel
=
pDescriptor
->
pColumnModel
;
if
(
compareFn
(
pDescriptor
,
numOfRows
,
midIdx
,
start
,
data
)
==
1
)
{
if
(
compareFn
(
pDescriptor
,
numOfRows
,
midIdx
,
start
,
data
)
==
1
)
{
swap
(
p
Descriptor
->
pColumnModel
,
numOfRows
,
start
,
data
,
midIdx
);
swap
(
p
Model
,
numOfRows
,
start
,
data
,
midIdx
,
buf
);
}
}
if
(
compareFn
(
pDescriptor
,
numOfRows
,
midIdx
,
end
,
data
)
==
1
)
{
if
(
compareFn
(
pDescriptor
,
numOfRows
,
midIdx
,
end
,
data
)
==
1
)
{
swap
(
p
Descriptor
->
pColumnModel
,
numOfRows
,
midIdx
,
data
,
start
);
swap
(
p
Model
,
numOfRows
,
midIdx
,
data
,
start
,
buf
);
swap
(
p
Descriptor
->
pColumnModel
,
numOfRows
,
midIdx
,
data
,
end
);
swap
(
p
Model
,
numOfRows
,
midIdx
,
data
,
end
,
buf
);
}
else
if
(
compareFn
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
)
==
1
)
{
}
else
if
(
compareFn
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
)
==
1
)
{
swap
(
p
Descriptor
->
pColumnModel
,
numOfRows
,
start
,
data
,
end
);
swap
(
p
Model
,
numOfRows
,
start
,
data
,
end
,
buf
);
}
}
assert
(
compareFn
(
pDescriptor
,
numOfRows
,
midIdx
,
start
,
data
)
<=
0
&&
assert
(
compareFn
(
pDescriptor
,
numOfRows
,
midIdx
,
start
,
data
)
<=
0
&&
...
@@ -626,32 +627,20 @@ static UNUSED_FUNC void tRowModelDisplay(tOrderDescriptor *pDescriptor, int32_t
...
@@ -626,32 +627,20 @@ static UNUSED_FUNC void tRowModelDisplay(tOrderDescriptor *pDescriptor, int32_t
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
static
int32_t
qsort_call
=
0
;
static
void
columnwiseQSortImpl
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
int32_t
orderType
,
__col_compar_fn_t
compareFn
,
void
*
buf
)
{
void
tColDataQSort
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
int32_t
orderType
)
{
// short array sort, incur another sort procedure instead of quick sort process
__col_compar_fn_t
compareFn
=
(
orderType
==
TSDB_ORDER_ASC
)
?
compare_sa
:
compare_sd
;
if
(
end
-
start
+
1
<=
8
)
{
tColDataInsertSort
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
);
return
;
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
//
printf("before sort:\n");
printf
(
"before sort:
\n
"
);
//
tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
tRowModelDisplay
(
pDescriptor
,
numOfRows
,
data
,
end
-
start
+
1
);
#endif
#endif
int32_t
s
=
start
,
e
=
end
;
int32_t
s
=
start
,
e
=
end
;
median
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
);
median
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
,
buf
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
// printf("%s called: %d\n", __FUNCTION__, qsort_call++);
// printf("%s called: %d\n", __FUNCTION__, qsort_call++);
#endif
#endif
UNUSED
(
qsort_call
);
int32_t
end_same
=
end
;
int32_t
end_same
=
end
;
int32_t
start_same
=
start
;
int32_t
start_same
=
start
;
...
@@ -663,17 +652,17 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
...
@@ -663,17 +652,17 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
}
}
if
(
ret
==
0
&&
e
!=
end_same
)
{
if
(
ret
==
0
&&
e
!=
end_same
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
e
,
data
,
end_same
--
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
e
,
data
,
end_same
--
,
buf
);
}
}
e
--
;
e
--
;
}
}
if
(
e
!=
s
)
{
if
(
e
!=
s
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
s
,
data
,
e
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
s
,
data
,
e
,
buf
);
}
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
#endif
#endif
while
(
s
<
e
)
{
while
(
s
<
e
)
{
...
@@ -683,16 +672,16 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
...
@@ -683,16 +672,16 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
}
}
if
(
ret
==
0
&&
s
!=
start_same
)
{
if
(
ret
==
0
&&
s
!=
start_same
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
s
,
data
,
start_same
++
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
s
,
data
,
start_same
++
,
buf
);
}
}
s
++
;
s
++
;
}
}
if
(
s
!=
e
)
{
if
(
s
!=
e
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
s
,
data
,
e
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
s
,
data
,
e
,
buf
);
}
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
#endif
#endif
}
}
...
@@ -702,14 +691,14 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
...
@@ -702,14 +691,14 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
int32_t
right
=
end
;
int32_t
right
=
end
;
while
(
right
>
end_same
&&
left
<=
end_same
)
{
while
(
right
>
end_same
&&
left
<=
end_same
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
left
++
,
data
,
right
--
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
left
++
,
data
,
right
--
,
buf
);
}
}
// (pivotal+1) + steps of number that are identical pivotal
// (pivotal+1) + steps of number that are identical pivotal
rightx
+=
(
end
-
end_same
);
rightx
+=
(
end
-
end_same
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
#endif
#endif
}
}
...
@@ -719,26 +708,52 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
...
@@ -719,26 +708,52 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta
int32_t
right
=
e
-
1
;
int32_t
right
=
e
-
1
;
while
(
left
<
start_same
&&
right
>=
start_same
)
{
while
(
left
<
start_same
&&
right
>=
start_same
)
{
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
left
++
,
data
,
right
--
);
swap
(
pDescriptor
->
pColumnModel
,
numOfRows
,
left
++
,
data
,
right
--
,
buf
);
}
}
// (pivotal-1) - steps of number that are identical pivotal
// (pivotal-1) - steps of number that are identical pivotal
leftx
-=
(
start_same
-
start
);
leftx
-=
(
start_same
-
start
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
// tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1);
#endif
#endif
}
}
if
(
leftx
>
start
)
{
if
(
leftx
>
start
)
{
tColDataQSort
(
pDescriptor
,
numOfRows
,
start
,
leftx
,
data
,
orderType
);
columnwiseQSortImpl
(
pDescriptor
,
numOfRows
,
start
,
leftx
,
data
,
orderType
,
compareFn
,
buf
);
}
}
if
(
rightx
<
end
)
{
if
(
rightx
<
end
)
{
tColDataQSort
(
pDescriptor
,
numOfRows
,
rightx
,
end
,
data
,
orderType
);
columnwiseQSortImpl
(
pDescriptor
,
numOfRows
,
rightx
,
end
,
data
,
orderType
,
compareFn
,
buf
);
}
}
}
}
void
tColDataQSort
(
tOrderDescriptor
*
pDescriptor
,
int32_t
numOfRows
,
int32_t
start
,
int32_t
end
,
char
*
data
,
int32_t
order
)
{
// short array sort, incur another sort procedure instead of quick sort process
__col_compar_fn_t
compareFn
=
(
order
==
TSDB_ORDER_ASC
)
?
compare_sa
:
compare_sd
;
SColumnModel
*
pModel
=
pDescriptor
->
pColumnModel
;
size_t
width
=
0
;
for
(
int32_t
i
=
0
;
i
<
pModel
->
numOfCols
;
++
i
)
{
SSchema
*
pSchema
=
&
pModel
->
pFields
[
i
].
field
;
if
(
width
<
pSchema
->
bytes
)
{
width
=
pSchema
->
bytes
;
}
}
char
*
buf
=
malloc
(
width
);
assert
(
width
>
0
&&
buf
!=
NULL
);
if
(
end
-
start
+
1
<=
8
)
{
tColDataInsertSort
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
compareFn
,
buf
);
}
else
{
columnwiseQSortImpl
(
pDescriptor
,
numOfRows
,
start
,
end
,
data
,
order
,
compareFn
,
buf
);
}
free
(
buf
);
}
/*
/*
* deep copy of sschema
* deep copy of sschema
*/
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录