记录stonedb的子查询处理
- void ParameterizedFilter::ApplyDescriptor(int desc_number, int64_t limit)
- // desc_number = -1 => switch off the rough part
- {
- Descriptor &desc = descriptors[desc_number];
- if (desc.op == common::Operator::O_TRUE) {
- desc.done = true;
- return;
- }
- if (desc.op == common::Operator::O_FALSE) {
- mind->Empty();
- desc.done = true;
- return;
- }
-
- DimensionVector dims(mind->NoDimensions());
- desc.DimensionUsed(dims);
- mind->MarkInvolvedDimGroups(dims); // create iterators on whole groups (important for
- // multidimensional updatable iterators)
- int no_dims = dims.NoDimsUsed();
- if (no_dims == 0 && !desc.IsDeterministic()) dims.SetAll();
- // Check the easy case (one-dim, parallelizable)
- int one_dim = -1;
- common::RSValue *rf = NULL;
- if (no_dims == 1) {
- for (int i = 0; i < mind->NoDimensions(); i++) {
- if (dims[i]) {
- if (mind->GetFilter(i)) one_dim = i; // exactly one filter (non-join or join with forgotten dims)
- break;
- }
- }
- }
- if (one_dim != -1)
- rf = rough_mind->GetLocalDescFilter(one_dim, desc_number,
- true); // "true" here means that we demand an existing local rough
- // filter
-
- int packs_no = (int)((mind->OrigSize(one_dim) + ((1 << mind->NoPower()) - 1)) >> mind->NoPower());
- int pack_all = rough_mind->NoPacks(one_dim);
- int pack_some = 0;
- for (int b = 0; b < pack_all; b++) {
- if (rough_mind->GetPackStatus(one_dim, b) != common::RSValue::RS_NONE) pack_some++;
- }
- MIUpdatingIterator mit(mind, dims);
- desc.CopyDesCond(mit);
- if (desc.EvaluateOnIndex(mit, limit) == common::ErrorCode::SUCCESS) {
- rccontrol.lock(mind->m_conn->GetThreadID())
- << "EvaluateOnIndex done, desc number " << desc_number << system::unlock;
- } else {
- int poolsize = rceng->query_thread_pool.size();
- if ((stonedb_sysvar_threadpoolsize > 0) && (packs_no / poolsize > 0) && !desc.IsType_Subquery() &&
- !desc.ExsitTmpTable()) {
- int step = 0;
- int task_num = 0;
- /*Partition task slice*/
- if (pack_some <= poolsize) {
- task_num = poolsize;
- } else {
- step = pack_some / poolsize;
- task_num = packs_no / step;
- }
- int mod = packs_no % task_num;
- int num = packs_no / task_num;
-
- desc.InitParallel(task_num, mit);
-
- std::vector<MultiIndex> mis;
- mis.reserve(task_num);
-
- std::vector<MIUpdatingIterator> taskIterator;
- taskIterator.reserve(task_num);
-
- for (int i = 0; i < task_num; ++i) {
- auto &mi = mis.emplace_back(*mind, true);
- int pstart = ((i == 0) ? 0 : mod + i * num);
- int pend = mod + (i + 1) * num - 1;
-
- auto &mii = taskIterator.emplace_back(&mi, dims);
- mii.SetTaskNum(task_num);
- mii.SetTaskId(i);
- mii.SetNoPacksToGo(pend);
- mii.RewindToPack(pstart);
- }
-
- utils::result_set<void> res;
- for (int i = 0; i < task_num; ++i) {
- res.insert(rceng->query_thread_pool.add_task(&ParameterizedFilter::TaskProcessPacks, this, &taskIterator[i],
- current_tx, rf, &dims, desc_number, limit, one_dim));
- }
- res.get_all_with_except();
-
- if (mind->m_conn->Killed()) throw common::KilledException("catch thread pool Exception: TaskProcessPacks");
- mind->UpdateNoTuples();
-
- } else {
- common::RSValue cur_roughval;
- uint64_t passed = 0;
- int pack = -1;
- while (mit.IsValid()) {
- if (limit != -1 && rf) { // rf - not null if there is one dim only
- // (otherwise packs make no sense)
- if (passed >= (uint64_t)limit) {
- mit.ResetCurrentPack();
- mit.NextPackrow();
- continue;
- }
- if (mit.PackrowStarted()) {
- if (pack != -1) passed += mit.NoOnesUncommited(pack);
- pack = mit.GetCurPackrow(one_dim);
- }
- }
-
- if (rf && mit.GetCurPackrow(one_dim) >= 0)
- cur_roughval = rf[mit.GetCurPackrow(one_dim)];
- else
- cur_roughval = common::RSValue::RS_SOME;
-
- if (cur_roughval == common::RSValue::RS_NONE) {
- mit.ResetCurrentPack();
- mit.NextPackrow();
- } else if (cur_roughval == common::RSValue::RS_ALL) {
- mit.NextPackrow();
- } else {
- // common::RSValue::RS_SOME or common::RSValue::RS_UNKNOWN
- desc.EvaluatePack(mit);
- }
- if (mind->m_conn->Killed()) throw common::KilledException();
- }
- mit.Commit();
- }
- }
- desc.done = true;
- if (one_dim != -1 && mind->GetFilter(one_dim)) { // update global rough part
- Filter *f = mind->GetFilter(one_dim);
- for (int p = 0; p < rough_mind->NoPacks(one_dim); p++)
- if (f->IsEmpty(p)) {
- rough_mind->SetPackStatus(one_dim, p, common::RSValue::RS_NONE);
- }
- }
- desc.UpdateVCStatistics();
- return;
- }
- common::RSValue cur_roughval;
- uint64_t passed = 0;
- int pack = -1;
- while (mit.IsValid()) {
- if (limit != -1 && rf) { // rf - not null if there is one dim only
- // (otherwise packs make no sense)
- if (passed >= (uint64_t)limit) {
- mit.ResetCurrentPack();
- mit.NextPackrow();
- continue;
- }
- if (mit.PackrowStarted()) {
- if (pack != -1) passed += mit.NoOnesUncommited(pack);
- pack = mit.GetCurPackrow(one_dim);
- }
- }
-
- if (rf && mit.GetCurPackrow(one_dim) >= 0)
- cur_roughval = rf[mit.GetCurPackrow(one_dim)];
- else
- cur_roughval = common::RSValue::RS_SOME;
-
- if (cur_roughval == common::RSValue::RS_NONE) {
- mit.ResetCurrentPack();
- mit.NextPackrow();
- } else if (cur_roughval == common::RSValue::RS_ALL) {
- mit.NextPackrow();
- } else {
- // common::RSValue::RS_SOME or common::RSValue::RS_UNKNOWN
- desc.EvaluatePack(mit);
- }
- if (mind->m_conn->Killed()) throw common::KilledException();
- }
- mit.Commit();
- (gdb) bt
- #0 stonedb::core::ParameterizedFilter::ApplyDescriptor (this=0x7fa8d404e7a0, desc_number=0, limit=-1)
- at /root/work/stonedb/storage/stonedb/core/parameterized_filter.cpp:1306
- #1 0x0000000001d4ef85 in stonedb::core::ParameterizedFilter::UpdateMultiIndex (this=0x7fa8d404e7a0, count_only=false, limit=-1)
- at /root/work/stonedb/storage/stonedb/core/parameterized_filter.cpp:1053
- #2 0x00000000019e95e0 in stonedb::core::Query::Preexecute (this=0x7fa8d4027780, qu=..., sender=0x0, display_now=false)
- at /root/work/stonedb/storage/stonedb/core/query.cpp:776
- #3 0x0000000001d9172e in stonedb::dbhandler::StonedbHandler::set_cond_iter (this=0x7fa8d4034910)
- at /root/work/stonedb/storage/stonedb/handler/stonedb_handler.cpp:1315
- #4 0x0000000001d92482 in stonedb::dbhandler::StonedbHandler::cond_push (this=0x7fa8d4034910, a_cond=0x7fa8d4044f20)
- at /root/work/stonedb/storage/stonedb/handler/stonedb_handler.cpp:1399
- #5 0x000000000154590e in make_join_select (join=0x7fa8d4043930, cond=0x7fa8d404b710) at /root/work/stonedb/sql/sql_optimizer.cc:7806
- #6 0x0000000001533ae4 in JOIN::optimize (this=0x7fa8d4043930, part=0 '\000') at /root/work/stonedb/sql/sql_optimizer.cc:513
- #7 0x00000000014c720c in subselect_single_select_engine::exec (this=0x7fa8d40093a0) at /root/work/stonedb/sql/item_subselect.cc:2747
- #8 0x00000000014c07c5 in Item_subselect::exec (this=0x7fa8d404b800) at /root/work/stonedb/sql/item_subselect.cc:642
- #9 0x00000000014c26d6 in Item_exists_subselect::val_int (this=0x7fa8d404b800) at /root/work/stonedb/sql/item_subselect.cc:1269
- #10 0x000000000125338c in eval_const_cond (cond=0x7fa8d404b800) at /root/work/stonedb/sql/item_func.cc:76
- #11 0x0000000001548155 in internal_remove_eq_conds (thd=0x41658a0, cond=0x7fa8d404b800, cond_value=0x7fa90140b6dc, part=1 '\001')
- at /root/work/stonedb/sql/sql_optimizer.cc:8681
- #12 0x0000000001547c68 in internal_remove_eq_conds (thd=0x41658a0, cond=0x7fa8d40089e0, cond_value=0x4167e38, part=1 '\001')
- at /root/work/stonedb/sql/sql_optimizer.cc:8552
- #13 0x0000000001548516 in remove_eq_conds (thd=0x41658a0, cond=0x7fa8d40089e0, cond_value=0x4167e38, part=1 '\001') at /root/work/stonedb/sql/sql_optimizer.cc:8774
- #14 0x00000000015479da in optimize_cond (thd=0x41658a0, conds=0x7fa8d40089e0, cond_equal=0x7fa8d404c008, join_list=0x4167ee8, build_equalities=true,
- cond_value=0x4167e38, part=1 '\001') at /root/work/stonedb/sql/sql_optimizer.cc:8507
- #15 0x00000000015329cf in JOIN::optimize (this=0x7fa8d404bca0, part=1 '\001') at /root/work/stonedb/sql/sql_optimizer.cc:246
- #16 0x00000000019b7c3e in stonedb::core::optimize_select (thd=0x41658a0, tables=0x7fa8d4007ac0, wild_num=0, fields=..., conds=0x7fa8d40089e0, og_num=2,
- order=0x7fa8d404bb80, group=0x7fa8d404ba20, having=0x0, select_options=2147748608, result=0x7fa8d404bc68, unit=0x4167720, select_lex=0x4167d68,
- optimize_after_sdb=@0x7fa90140c094: 1, free_join=@0x7fa90140c098: 1) at /root/work/stonedb/storage/stonedb/core/engine_execute.cpp:339
- #17 0x00000000019b7588 in stonedb::core::Engine::HandleSelect (this=0x41b1150, thd=0x41658a0, lex=0x4167660, result=@0x7fa90140c0a0: 0x7fa8d404bc68,
- setup_tables_done_option=0, res=@0x7fa90140c09c: 0, optimize_after_sdb=@0x7fa90140c094: 1, sdb_free_join=@0x7fa90140c098: 1, with_insert=0)
- at /root/work/stonedb/storage/stonedb/core/engine_execute.cpp:223
- #18 0x0000000001aacee3 in stonedb::dbhandler::SDB_HandleSelect (thd=0x41658a0, lex=0x4167660, result=@0x7fa90140c0a0: 0x7fa8d404bc68, setup_tables_done_option=0,
- res=@0x7fa90140c09c: 0, optimize_after_sdb=@0x7fa90140c094: 1, sdb_free_join=@0x7fa90140c098: 1, with_insert=0)
- at /root/work/stonedb/storage/stonedb/handler/ha_rcengine.cpp:82
- #19 0x000000000137b090 in execute_sqlcom_select (thd=0x41658a0, all_tables=0x7fa8d4007ac0)
- #20 0x0000000001373ea1 in mysql_execute_command (thd=0x41658a0)
- #21 0x000000000137daec in mysql_parse (thd=0x41658a0,
- rawbuf=0x7fa8d40073f0 "select\n o_carrier_id,\n count(*) as order_count\nfrom\n orders\nwhere\n o_entry_d >= date '1993-07-01'\n and o_entry_d < date '2022-07-06' + interval '3' month\n and exists (\n select"..., length=374, parser_state=0x7fa90140d170)
- #22 0x000000000137109d in dispatch_command (command=COM_QUERY, thd=0x41658a0,
- packet=0x4168bf1 "select\n o_carrier_id,\n count(*) as order_count\nfrom\n orders\nwhere\n o_entry_d >= date '1993-07-01'\n and o_entry_d < date '2022-07-06' + interval '3' month\n and exists (\n select"..., packet_length=374)
- #23 0x00000000013701d7 in do_command (thd=0x41658a0)
- #24 0x000000000133be43 in do_handle_one_connection (thd_arg=0x41658a0) at /root/work/stonedb/sql/sql_connect.cc:982
- #25 0x000000000133b9a6 in handle_one_connection (arg=0x41658a0) at /root/work/stonedb/sql/sql_connect.cc:898
- #26 0x00000000019530a2 in pfs_spawn_thread (arg=0x4842510) at /root/work/stonedb/storage/perfschema/pfs.cc:1860
- #27 0x00007faa73470ea5 in start_thread () from /lib64/libpthread.so.0
- #28 0x00007faa71f7cb0d in clone () from /lib64/libc.so.6
- (gdb) p mit
- $6 = {
- <stonedb::core::MIIterator> = {
- _vptr.MIIterator = 0x24b1578 <vtable for stonedb::core::MIUpdatingIterator+16>,
- it = std::vector of length 1, capacity 1 = {0x7fa8d404e9b0},
- dg = std::vector of length 1, capacity 1 = {0x7fa8d401aa80},
- it_for_dim = 0x7fa8d4047b60,
- mind = 0x7fa8d404e900,
- mind_created_locally = false,
- no_dims = 1,
- dimensions = {
- v = std::vector<bool> of length 1, capacity 64 = {1}
- },
- cur_pos = 0x7fa8d4046ee0,
- cur_pack = 0x7fa8d4027980,
- valid = true,
- omitted_factor = 1,
- no_obj = 100000,
- p_power = 16,
- pack_size_left = 65536,
- next_pack_started = true,
- mii_type = stonedb::core::MIIterator::MII_NORMAL,
- po = std::vector of length 0, capacity 0,
- one_filter_dim = 0,
- one_filter_it = 0x7fa8d404e9b0,
- TaskId = 0,
- TasksNum = 1
- },
- members of stonedb::core::MIUpdatingIterator:
- pack_power = 16,
- changed = false,
- Python Exception <class 'gdb.error'> There is no member or method named _M_head_impl.:
- multi_dim_filter = ,
- multi_filter_pos = 0,
- multi_filter_pack_start = 0
- }
- (gdb) ptype mit
- type = class stonedb::core::MIUpdatingIterator : public stonedb::core::MIIterator {
- private:
- uint32_t pack_power;
- bool changed;
- std::unique_ptr<stonedb::core::Filter, std::default_delete<stonedb::core::Filter> > multi_dim_filter;
- int64_t multi_filter_pos;
- int64_t multi_filter_pack_start;
-
- public:
- MIUpdatingIterator(stonedb::core::MultiIndex *, stonedb::core::DimensionVector &);
- MIUpdatingIterator(const stonedb::core::MIUpdatingIterator &);
- MIUpdatingIterator(stonedb::core::MIUpdatingIterator &);
- stonedb::core::MIUpdatingIterator & operator=(const stonedb::core::MIUpdatingIterator &);
- ~MIUpdatingIterator(int);
- void ResetCurrent(void);
- void ResetCurrentPack(void);
- void Commit(bool);
- void Rewind(void);
- stonedb::core::MIUpdatingIterator & operator++(void);
- virtual void NextPackrow(void);
- void RewindToRow(int64_t);
- virtual bool RewindToPack(int);
- int NoOnesUncommited(uint);
- void UpdateNoTuples(void);
- int SingleFilterDim(void) const;
- stonedb::core::Filter * NewPackFilter(int);
- bool SwapPackFilter(int, stonedb::core::Filter *);
- void OrPackFilter(int, stonedb::core::Filter *);
- }