-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
bug: SQL-Q16 unnecessary memcpy of buffer when aggregate rows #408
Comments
摘要: 分析: 简要日志追踪:
详细日志追踪:
逻辑分析: 受影响多执行的函数: for (int gr_a = 0; gr_a < gbw.NumOfGroupingAttrs(); gr_a++)
if (gbw.ColumnNotOmitted(gr_a)) {
gbw.PutGroupingValue(gr_a, *mit);
++num_put;
}
void PutGroupingValue(int col, MIIterator &mit) {
// Encoder statistics are not updated here
encoder[col]->Encode(input_buffer.data(), mit);
// TIANMU_LOG(LogCtl_Level::INFO, "PutGroupingValue over encode col:%d input_buffer.size: %d",
// col,input_buffer.size());
}
void ColumnBinEncoder::EncoderText_UTF::Encode(uchar *buf, uchar *buf_sec, vcolumn::VirtualColumn *vc, MIIterator &mit,
bool update_stats) {
if (null_status > 0 && vc->IsNull(mit)) {
SetNull(buf, buf_sec);
return;
}
std::memset(buf, 0, size);
types::BString s;
vc->GetNotNullValueString(s, mit);
if (update_stats) {
if (!min_max_set) {
maxs.PersistentCopy(s);
mins.PersistentCopy(s);
min_max_set = true;
} else {
if (CollationStrCmp(collation, s, maxs) > 0) maxs.PersistentCopy(s);
if (CollationStrCmp(collation, s, mins) < 0) mins.PersistentCopy(s);
}
}
common::strnxfrm(collation, buf, size - sizeof(uint32_t), (uchar *)s.GetDataBytesPointer(), s.len);
// TIANMU_LOG(LogCtl_Level::INFO, "EncoderText_UTF::Encode buf_size: %d s.len: %d s: [%s]", size, s.len, s.ToString().c_str());
for (int i = 0; i < size; ++i) {
if (!buf[i]) {
continue;
}
uchar x = buf[i];
// TIANMU_LOG(LogCtl_Level::INFO, "i:[%d] x:[%X]", i, x);
}
// int coded_len = types::CollationBufLen(collation, s.len);
uint32_t length = s.len + 1;
std::memcpy(buf + size - sizeof(uint32_t), &length, sizeof(uint32_t));
if (descending) Negate(buf, size);
if (size_sec > 0) {
std::memset(buf_sec, 0, size_sec);
std::memcpy(buf_sec + size_sec - sizeof(uint32_t), &length, sizeof(uint32_t));
if (s.len > 0) std::memcpy(buf_sec, s.GetDataBytesPointer(), s.len);
}
}
|
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f39be0a1700 (LWP 2796)]
0x00007f39c591b07c in _int_malloc () from /lib64/libc.so.6
(gdb) bt
#0 0x00007f39c591b07c in _int_malloc () from /lib64/libc.so.6
#1 0x00007f39c591e78c in malloc () from /lib64/libc.so.6
#2 0x00000000035a63f8 in operator new(unsigned long) ()
#3 0x0000000002e01a92 in __gnu_cxx::new_allocator<void*>::allocate (this=0x7f164c9c51d0, __n=2) at /opt/rh/devtoolset-7/root/usr/include/c++/7/ext/new_allocator.h:111
#4 0x0000000002dffe36 in std::allocator_traits<std::allocator<void*> >::allocate (__a=..., __n=2) at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/alloc_traits.h:436
#5 0x0000000002dfd724 in std::_Vector_base<void*, std::allocator<void*> >::_M_allocate (this=0x7f164c9c51d0, __n=2) at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_vector.h:172
#6 0x0000000002df9e8f in std::vector<void*, std::allocator<void*> >::_M_realloc_insert<void* const&> (this=0x7f164c9c51d0, __position=, __args#0=@0x7f39be09dbb8: 0x7f1666648000)
at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/vector.tcc:406
#7 0x0000000002df7740 in std::vector<void*, std::allocator<void*> >::push_back (this=0x7f164c9c51d0, __x=@0x7f39be09dbb8: 0x7f1666648000)
at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_vector.h:948
#8 0x00000000031d23b0 in Tianmu::core::BlockedRowMemStorage::AddEmptyRow (this=0x7f164c9c5198)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/blocked_mem_table.cpp:148
#9 0x00000000031ba012 in Tianmu::core::ValueMatching_HashTable::FindCurrentRow (this=0x7f164c9c50f0, input_buffer=0x7f164c000078 "", row=@0x7f39be09dd08: 65536, add_if_new=true)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/value_matching_hashtable.cpp:157
#10 0x0000000003064f98 in Tianmu::core::GroupTable::FindCurrentRow (this=0x7f39be09e2e8, row=@0x7f39be09dd08: 65536)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/group_table.cpp:403
#11 0x000000000300a872 in Tianmu::core::GroupByWrapper::FindCurrentRow (this=0x7f39be09e220, row=@0x7f39be09dd08: 65536)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/groupby_wrapper.h:109
#12 0x00000000030073bd in Tianmu::core::AggregationAlgorithm::AggregatePackrow (this=0x7f39be09e580, gbw=..., mit=0x7f39be09dee0, cur_tuple=65536)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/aggregation_algorithm.cpp:548
#13 0x0000000003005cc4 in Tianmu::core::AggregationAlgorithm::MultiDimensionalGroupByScan (this=0x7f39be09e580, gbw=..., limit=@0x7f39be09e208: 7422784, offset=@0x7f39be09e608: 0, sender=0x0,
limit_less_than_no_groups=false) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/aggregation_algorithm.cpp:280
#14 0x000000000300551a in Tianmu::core::AggregationAlgorithm::Aggregate (this=0x7f39be09e580, just_distinct=false, limit=@0x7f39be09e600: -1, offset=@0x7f39be09e608: 0, sender=0x0)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/aggregation_algorithm.cpp:196
#15 0x0000000002df1f8e in Tianmu::core::TempTable::Materialize (this=0x7f164c92c760, in_subq=false, sender=0x7f164c921550, lazy=false)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/temp_table.cpp:1972
#16 0x0000000002d3a564 in Tianmu::core::Engine::Execute (this=0x7b42010, thd=0x7f164c000b70, lex=0x7f164c002e98, result_output=0x7f164c01e1c0, unit_for_union=0x0)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/engine_execute.cpp:426
#17 0x0000000002d39706 in Tianmu::core::Engine::HandleSelect (this=0x7b42010, thd=0x7f164c000b70, lex=0x7f164c002e98, result=@0x7f39be09ed18: 0x7f164c01e1c0, setup_tables_done_option=0,
res=@0x7f39be09ed14: 0, optimize_after_tianmu=@0x7f39be09ed0c: 1, tianmu_free_join=@0x7f39be09ed10: 1, with_insert=0)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/core/engine_execute.cpp:232
#18 0x0000000002e21f97 in Tianmu::dbhandler::TIANMU_HandleSelect (thd=0x7f164c000b70, lex=0x7f164c002e98, result=@0x7f39be09ed18: 0x7f164c01e1c0, setup_tables_done_option=0, res=@0x7f39be09ed14: 0,
optimize_after_tianmu=@0x7f39be09ed0c: 1, tianmu_free_join=@0x7f39be09ed10: 1, with_insert=0)
at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/tianmu/handler/ha_rcengine.cpp:82
#19 0x00000000024630ba in execute_sqlcom_select (thd=0x7f164c000b70, all_tables=0x7f164c01af98) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/sql/sql_parse.cc:5182
#20 0x000000000245c43e in mysql_execute_command (thd=0x7f164c000b70, first_level=true) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/sql/sql_parse.cc:2831
#21 0x0000000002464083 in mysql_parse (thd=0x7f164c000b70, parser_state=0x7f39be09feb0) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/sql/sql_parse.cc:5621
#22 0x000000000245931b in dispatch_command (thd=0x7f164c000b70, com_data=0x7f39be0a0650, command=COM_QUERY) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/sql/sql_parse.cc:1495
#23 0x0000000002458247 in do_command (thd=0x7f164c000b70) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/sql/sql_parse.cc:1034
#24 0x000000000258ae1d in handle_connection (arg=0x80e1c80) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/sql/conn_handler/connection_handler_per_thread.cc:313
#25 0x0000000002c71252 in pfs_spawn_thread (arg=0x15a07df0) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-119-20220805/storage/perfschema/pfs.cc:2197
#26 0x00007f39c7762ea5 in start_thread () from /lib64/libpthread.so.0
#27 0x00007f39c5997b0d in clone () from /lib64/libc.so.6
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the problem
摘要:
追踪在单线程中耗时的处理
耗时追踪:
日志埋点追踪:
调用堆栈:
核心函数:
ColumnBinEncoder::EncoderText_UTF::Encode
该函数原始实现:
耗时原因分析:
一. like string 的子条件被判定为需要走聚合
二. 聚合时将string类型的值都做了一次memcpy
Expected behavior
No response
How To Reproduce
No response
Environment
No response
Are you interested in submitting a PR to solve the problem?
The text was updated successfully, but these errors were encountered: