diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2022-06-24 01:45:44 +0300 |
---|---|---|
committer | Nikita Malyavin <nikitamalyavin@gmail.com> | 2022-06-24 01:45:44 +0300 |
commit | 074c211faf9cd5ce8d0e6104ef5685e8f4c9d8f3 (patch) | |
tree | f1342843be757793c9e8a99a5dc9e340c433ba8e | |
parent | 69af61a4ee04fa22efb5a35b2e91fb1a809170de (diff) | |
download | mariadb-git-074c211faf9cd5ce8d0e6104ef5685e8f4c9d8f3.tar.gz |
sampling analysiskakurin_sampling
file=open(...)
for l in file:
if l.startswith('SAMPLE') and not l.startswith('SAMPLE root'):
print(l)
n = dict((p.split('=')
for p in l.replace('SAMPLE ', '').replace(' REJECT', '').split()
))
if 'REJECT' in l:
n['rej']=True
nodes.append(n)
max(int(n['size']) for n in nodes)
max((float(n['p']), serialize(n)) for n in nodes)
max((float(n['size']), serialize(n)) for n in nodes if n['height'] == '0')
-rw-r--r-- | mysql-test/main/profile.opt | 2 | ||||
-rw-r--r-- | mysql-test/main/profile.test | 34 | ||||
-rw-r--r-- | storage/innobase/btr/btr0cur.cc | 16 | ||||
-rw-r--r-- | storage/innobase/page/page0cur.cc | 10 |
4 files changed, 26 insertions, 36 deletions
diff --git a/mysql-test/main/profile.opt b/mysql-test/main/profile.opt index da84f76d539..8fbae672382 100644 --- a/mysql-test/main/profile.opt +++ b/mysql-test/main/profile.opt @@ -1,2 +1,2 @@ ---innodb_buffer_pool_size=8M +--innodb_buffer_pool_size=1G diff --git a/mysql-test/main/profile.test b/mysql-test/main/profile.test index dcff6e480ae..b1c7bc21d9a 100644 --- a/mysql-test/main/profile.test +++ b/mysql-test/main/profile.test @@ -50,7 +50,7 @@ create or replace temporary table counters ( ) engine=myisam; ---let $i= 500 +--let $i= 5 --echo i=$i --let $method=bernoulli --let percent=1 @@ -67,36 +67,4 @@ create or replace temporary table counters ( --enable_result_log select pk_value div 10000, sum(counter) from counters group by pk_value div 10000; -create or replace temporary table counters ( - pk_value int, - counter int, - primary key (pk_value) -) engine=myisam; - - ---echo ================================================================== ---echo ================================================================== ---echo ================================================================== ---echo ================================================================== ---echo ================================================================== ---echo ================================================================== ---echo ================================================================== ---echo ================================================================== - ---let $i= 500 ---echo i=$i ---let $method=system ---let percent=1 ---echo method=$method $percent% ---while($i) - eval -INSERT INTO counters - SELECT _id, 0 FROM vehicle_reg tablesample $method($percent) -ON DUPLICATE KEY UPDATE counter = counter + 1 -; ---dec $i ---} ---enable_query_log ---enable_result_log -select pk_value div 10000, sum(counter) from counters group by pk_value div 10000; --} diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 04ee06bf032..027ef598d50 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -2847,6 +2847,7 @@ btr_cur_open_at_index_side( return err; } extern unsigned long long my_counter; +ulint get_last_nth(); /**********************************************************************//** Positions a cursor at a randomly chosen position within a B-tree. @return DB_SUCCESS if the index is available and we have put the cursor, @@ -2952,8 +2953,10 @@ btr_cur_open_at_rnd_pos( } height = ULINT_UNDEFINED; + fprintf(stderr, "SAMPLE root page_id=%d\n", page_id.page_no()); for (;;) { + bool root= false; page_t* page; ut_ad(n_blocks < BTR_MAX_LEVELS); @@ -3012,6 +3015,7 @@ btr_cur_open_at_rnd_pos( /* We are in the root node */ height = btr_page_get_level(page); + root= true; } else { if(sim_uniform_dist) { ulint n_recs = page_get_n_recs(block->page.frame); @@ -3059,6 +3063,12 @@ btr_cur_open_at_rnd_pos( page_cur_open_on_rnd_user_rec(block, page_cursor); + fprintf(stderr, "SAMPLE node=%x root=%d p=%lf height=%ld size=%d child_no=%ld ", + page_id.page_no(), root, + p, + height, + page_get_n_recs(block->page.frame), + get_last_nth()); if (height == 0) { break; @@ -3145,6 +3155,8 @@ btr_cur_open_at_rnd_pos( page_id.set_page_no( btr_node_ptr_get_child_page_no(node_ptr, offsets)); + fprintf(stderr, "child_page=%x\n", page_id.page_no()); + n_blocks++; } @@ -3156,10 +3168,12 @@ btr_cur_open_at_rnd_pos( // getting 0..1 pseudo random number from ut_rnd_gen() // and exchange division by multiplication like // (b / c) < a <=> b < (a * c) - if(sim_uniform_dist && (ut_rnd_gen() < (p * ~(uint32_t)0))) { + if(sim_uniform_dist && (ut_rnd_gen() > (p * ~(uint32_t)0))) { err = DB_RECORD_NOT_FOUND; my_counter++; + fprintf(stderr, "REJECT\n"); } + else fprintf(stderr, "\n"); return err; } diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc index 41ae2638f47..ea5bd0da007 100644 --- a/storage/innobase/page/page0cur.cc +++ b/storage/innobase/page/page0cur.cc @@ -764,6 +764,13 @@ up_rec_match: } #endif /* BTR_CUR_HASH_ADAPT */ + +thread_local ulint last_nth; +ulint get_last_nth() +{ + return last_nth; +} + /***********************************************************//** Positions a page cursor on a randomly chosen user record on a page. If there are no user records, sets the cursor on the infimum record. */ @@ -782,8 +789,9 @@ page_cur_open_on_rnd_user_rec( return; } + last_nth= ut_rnd_interval(n_recs) + 1; cursor->rec = page_rec_get_nth(block->page.frame, - ut_rnd_interval(n_recs) + 1); + last_nth); } /** |