diff options
Diffstat (limited to 'sql/handler.h')
-rw-r--r-- | sql/handler.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/sql/handler.h b/sql/handler.h index 8f9ddc01174..d40e986fd9d 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1906,6 +1906,11 @@ enum enum_stats_auto_recalc { HA_STATS_AUTO_RECALC_DEFAULT= 0, HA_STATS_AUTO_RECALC_ON, HA_STATS_AUTO_RECALC_OFF }; +enum sample_mode { + HA_SAMPLE_BERNOULLI= 0, + HA_SAMPLE_SYSTEM, +}; + /** A helper struct for schema DDL statements: CREATE SCHEMA [IF NOT EXISTS] name [ schema_specification... ] @@ -2940,9 +2945,11 @@ public: /** Length of ref (1-8 or the clustered key length) */ uint ref_length; FT_INFO *ft_handler; - enum init_stat { NONE=0, INDEX, RND, RANDOM }; + enum init_stat { NONE=0, INDEX, RND, SAMPLE }; init_stat inited, pre_inited; + double sample_fraction= 0; + enum sample_mode sample_mode; const COND *pushed_cond; /** next_insert_id is the next value which should be inserted into the @@ -3105,21 +3112,25 @@ public: virtual int prepare_range_scan(const key_range *start_key, const key_range *end_key) { return 0; } - virtual int ha_random_sample_init(THD *thd, ha_rows estimate_rows_read) + int ha_random_sample_init(THD *thd, enum sample_mode mode, double fraction) __attribute__((warn_unused_result)) { DBUG_ENTER("ha_random_sample_init"); - inited= RANDOM; - DBUG_RETURN(random_sample_init(thd, estimate_rows_read)); + DBUG_ASSERT(inited==NONE); + int result; + sample_mode= mode; + sample_fraction= fraction; + inited= (result= random_sample_init(mode, fraction)) ? NONE : SAMPLE; + DBUG_RETURN(result); } - virtual int ha_random_sample(uchar *buf) + int ha_random_sample(uchar *buf) __attribute__((warn_unused_result)) { DBUG_ENTER("ha_random_sample"); - DBUG_ASSERT(inited == RANDOM); + DBUG_ASSERT(inited == SAMPLE); DBUG_RETURN(random_sample(buf)); } - virtual int ha_random_sample_end() __attribute__((warn_unused_result)) + int ha_random_sample_end() { DBUG_ENTER("ha_random_sample_end"); inited= NONE; @@ -4439,12 +4450,25 @@ private: /* Note: ha_index_read_idx_map() may bypass index_init() */ virtual int index_init(uint idx, bool sorted) { return 0; } virtual int index_end() { return 0; } - virtual int random_sample_init(MYSQL_THD thd, ha_rows estimate_rows_read) { return 0; } ; + virtual int random_sample_init(enum sample_mode mode, double fraction) + { + return rnd_init(TRUE); + } virtual int random_sample(uchar *buf) { - return HA_ERR_WRONG_COMMAND; + int rc; + THD *thd= ha_thd(); + do + { + rc= rnd_next(buf); + + if (rc == HA_ERR_RECORD_DELETED) + continue; + + } while (rc == HA_ERR_RECORD_DELETED || thd_rnd(thd) > sample_fraction); + return rc; } - virtual int random_sample_end() { return 0; }; + virtual int random_sample_end() { return rnd_end(); } /** rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1). |