diff options
author | monty@hundin.mysql.fi <> | 2002-10-16 13:11:25 +0300 |
---|---|---|
committer | monty@hundin.mysql.fi <> | 2002-10-16 13:11:25 +0300 |
commit | 67d3cd643b00d78e7236200f31efa9ec57a2083a (patch) | |
tree | d165b4baadac24102545d94c8f9fe180537a64f5 /innobase/btr/btr0cur.c | |
parent | 3712931cc6afb555146f668c63a8cba3bed33274 (diff) | |
parent | 87351da2040a11613d9f7b9aef05cab945b5ee2f (diff) | |
download | mariadb-git-67d3cd643b00d78e7236200f31efa9ec57a2083a.tar.gz |
Merge with 3.23.54
Diffstat (limited to 'innobase/btr/btr0cur.c')
-rw-r--r-- | innobase/btr/btr0cur.c | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/innobase/btr/btr0cur.c b/innobase/btr/btr0cur.c index e35ff2ca69e..3d6b63def6c 100644 --- a/innobase/btr/btr0cur.c +++ b/innobase/btr/btr0cur.c @@ -2531,7 +2531,7 @@ btr_cur_add_path_info( /*********************************************************************** Estimates the number of rows in a given index range. */ -ulint +ib_longlong btr_estimate_n_rows_in_range( /*=========================*/ /* out: estimated number of rows */ @@ -2547,8 +2547,9 @@ btr_estimate_n_rows_in_range( btr_path_t* slot1; btr_path_t* slot2; ibool diverged; + ibool diverged_lot; ulint divergence_level; - ulint n_rows; + ib_longlong n_rows; ulint i; mtr_t mtr; @@ -2589,10 +2590,13 @@ btr_estimate_n_rows_in_range( /* We have the path information for the range in path1 and path2 */ n_rows = 1; - diverged = FALSE; - divergence_level = 1000000; - - for (i = 0; ; i++) { + diverged = FALSE; /* This becomes true when the path is not + the same any more */ + diverged_lot = FALSE; /* This becomes true when the paths are + not the same or adjacent any more */ + divergence_level = 1000000; /* This is the level where paths diverged + a lot */ + for (i = 0; ; i++) { ut_ad(i < BTR_PATH_ARRAY_N_SLOTS); slot1 = path1 + i; @@ -2608,13 +2612,36 @@ btr_estimate_n_rows_in_range( n_rows = n_rows * 2; } + + /* Do not estimate the number of rows in the range + to over 1 / 2 of the estimated rows in the whole + table */ + + if (n_rows > index->table->stat_n_rows / 2) { + n_rows = index->table->stat_n_rows / 2; + + /* If there are just 0 or 1 rows in the table, + then we estimate all rows are in the range */ + + if (n_rows == 0) { + n_rows = index->table->stat_n_rows; + } + } + return(n_rows); } if (!diverged && slot1->nth_rec != slot2->nth_rec) { + diverged = TRUE; + if (slot1->nth_rec < slot2->nth_rec) { n_rows = slot2->nth_rec - slot1->nth_rec; + + if (n_rows > 1) { + diverged_lot = TRUE; + divergence_level = i; + } } else { /* Maybe the tree has changed between searches */ @@ -2622,10 +2649,27 @@ btr_estimate_n_rows_in_range( return(10); } - divergence_level = i; + } else if (diverged && !diverged_lot) { + + if (slot1->nth_rec < slot1->n_recs + || slot2->nth_rec > 1) { + + diverged_lot = TRUE; + divergence_level = i; + + n_rows = 0; + + if (slot1->nth_rec < slot1->n_recs) { + n_rows += slot1->n_recs + - slot1->nth_rec; + } + + if (slot2->nth_rec > 1) { + n_rows += slot2->nth_rec - 1; + } + } + } else if (diverged_lot) { - diverged = TRUE; - } else if (diverged) { n_rows = (n_rows * (slot1->n_recs + slot2->n_recs)) / 2; } |