Commit 9f7ec585 authored by vasil's avatar vasil

branches/zip:

Fix Bug#43660 SHOW INDEXES/ANALYZE does NOT update cardinality for
indexes of InnoDB table

by replacing the pseudo random number generator with a better one (LCG).

This also fixes Mantis Issue#212.

Approved by:	Heikki (rb://110)
parent 1e4bb48b
......@@ -30,16 +30,49 @@ Created 10/4/1994 Heikki Tuuri
#include "page0zip.h"
#include "mtr0log.h"
#include "log0recv.h"
#include "ut0ut.h"
#ifndef UNIV_HOTBACKUP
#include "rem0cmp.h"
static ulint page_rnd = 976722341;
#ifdef PAGE_CUR_ADAPT
# ifdef UNIV_SEARCH_PERF_STAT
static ulint page_cur_short_succ = 0;
# endif /* UNIV_SEARCH_PERF_STAT */
/***********************************************************************
This is a linear congruential generator PRNG. Returns a pseudo random
number between 0 and 2^64-1 inclusive. The formula and the constants
being used are:
X[n+1] = (a * X[n] + c) mod m
where:
X[0] = ut_time_us(NULL)
a = 1103515245 (3^5 * 5 * 7 * 129749)
c = 12345 (3 * 5 * 823)
m = 18446744073709551616 (2^64)
*/
#define LCG_a 1103515245
#define LCG_c 12345
static
ib_uint64_t
page_cur_lcg_prng()
/*===============*/
/* out: number between 0 and 2^64-1 */
{
static ib_uint64_t lcg_current = 0;
static ibool initialized = FALSE;
if (!initialized) {
lcg_current = (ib_uint64_t) ut_time_us(NULL);
initialized = TRUE;
}
/* no need to "% 2^64" explicitly because lcg_current is
64 bit and this will be done anyway */
lcg_current = LCG_a * lcg_current + LCG_c;
return(lcg_current);
}
/********************************************************************
Tries a search shortcut based on the last insert. */
UNIV_INLINE
......@@ -524,9 +557,7 @@ page_cur_open_on_rnd_user_rec(
return;
}
page_rnd += 87584577;
rnd = page_rnd % n_recs;
rnd = (ulint) page_cur_lcg_prng() % n_recs;
do {
page_cur_move_to_next(cursor);
......@@ -1930,3 +1961,30 @@ page_cur_delete_rec(
ut_a(!page_zip || page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
}
#ifdef UNIV_COMPILE_TEST_FUNCS
/***********************************************************************
Print the first n numbers, generated by page_cur_lcg_prng() to make sure
(visually) that it works properly. */
void
test_page_cur_lcg_prng(
/*===================*/
int n) /* in: print first n numbers */
{
int i;
unsigned long long rnd;
for (i = 0; i < n; i++) {
rnd = page_cur_lcg_prng();
printf("%llu\t%%2=%llu %%3=%llu %%5=%llu %%7=%llu %%11=%llu\n",
rnd,
rnd % 2,
rnd % 3,
rnd % 5,
rnd % 7,
rnd % 11);
}
}
#endif /* UNIV_COMPILE_TEST_FUNCS */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment