summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorapostle <vladkakurin007@gmail.com>2022-05-04 15:01:12 +0000
committerapostle <vladkakurin007@gmail.com>2022-05-04 15:02:46 +0000
commit46a38452ac14770053b3a3575ccb9a8a5b17a915 (patch)
treebe86e3f3e44b95018d6dd320dd9055b372e0b880
parentaf87186c1d3f9eeab73bc38b1faa51ba17fa8017 (diff)
downloadmariadb-git-46a38452ac14770053b3a3575ccb9a8a5b17a915.tar.gz
prototype of sampling code
-rw-r--r--sql/handler.h4
-rw-r--r--sql/sql_statistics.cc13
-rw-r--r--storage/innobase/handler/ha_innodb.cc36
-rw-r--r--storage/innobase/handler/ha_innodb.h2
4 files changed, 53 insertions, 2 deletions
diff --git a/sql/handler.h b/sql/handler.h
index 8ad521e189a..305b2afdf6a 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -4030,6 +4030,10 @@ public:
virtual int ft_read(uchar *buf) { return HA_ERR_WRONG_COMMAND; }
virtual int rnd_next(uchar *buf)=0;
virtual int rnd_pos(uchar * buf, uchar *pos)=0;
+
+ virtual int sample_next(uchar *buf) { return 0;}
+
+
/**
This function only works for handlers having
HA_PRIMARY_KEY_REQUIRED_FOR_POSITION set.
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 1f034f490c8..ce856bc5204 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -2634,6 +2634,11 @@ int collect_statistics_for_table(THD *thd, TABLE *table)
table->collected_stats->cardinality_is_null= TRUE;
table->collected_stats->cardinality= 0;
+ int b = file->sample_next(table->record[0]);
+
+ b += 1;
+
+
if (thd->variables.sample_percentage == 0)
{
if (file->records() < MIN_THRESHOLD_FOR_SAMPLING)
@@ -2650,14 +2655,18 @@ int collect_statistics_for_table(THD *thd, TABLE *table)
for (field_ptr= table->field; *field_ptr; field_ptr++)
{
- table_field= *field_ptr;
+ table_field= *field_ptr;
if (!table_field->collected_stats)
- continue;
+ continue;
table_field->collected_stats->init(thd, table_field);
}
restore_record(table, s->default_values);
+
+
+
+
/* Perform a full table scan to collect statistics on 'table's columns */
if (!(rc= file->ha_rnd_init(TRUE)))
{
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 17a92a242fd..9d9a4453588 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -9489,6 +9489,42 @@ ha_innobase::rnd_next(
DBUG_RETURN(error);
}
+#include "../row/row0sel.cc"
+
+int
+ha_innobase::sample_next(
+/*=====================*/
+ uchar *buf)
+{
+ int rc= ha_rnd_init(TRUE);
+ rc = rc;
+ mtr_t mtr;
+ btr_pcur_t* pcur = m_prebuilt->pcur;
+ rec_t* rec;
+
+
+ rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
+ rec_offs* offsets = offsets_;
+ rec_offs_init(offsets_);
+ mtr.start();
+ dict_index_t* index = innobase_get_index(MAX_KEY);
+ bool res = btr_pcur_open_at_rnd_pos(index, BTR_SEARCH_LEAF, pcur, &mtr);
+
+ rec = btr_pcur_get_rec(pcur);
+
+ mem_heap_t* heap = NULL;
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields, ULINT_UNDEFINED, &heap);
+ res = row_sel_store_mysql_rec(
+ buf, m_prebuilt, rec, NULL, true,
+ index, offsets);
+
+ res = res;
+
+ mtr.commit();
+ ha_rnd_end();
+ return 0;
+}
+
/**********************************************************************//**
Fetches a row from the table based on a row reference.
@return 0, HA_ERR_KEY_NOT_FOUND, or error code */
diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h
index 08501859ec9..f82d61e66f6 100644
--- a/storage/innobase/handler/ha_innodb.h
+++ b/storage/innobase/handler/ha_innodb.h
@@ -155,6 +155,8 @@ public:
int rnd_next(uchar *buf) override;
+ int sample_next(uchar *buf) override;
+
int rnd_pos(uchar * buf, uchar *pos) override;
int ft_init() override;