--- ../mysql-5.0.27-orig/./sql/mysqld.cc 2006-10-20 17:22:27.000000000 -0700 +++ ./sql/mysqld.cc 2007-01-15 13:47:35.042618576 -0800 @@ -4609,6 +4609,7 @@ OPT_INNODB_SYNC_SPIN_LOOPS, OPT_INNODB_CONCURRENCY_TICKETS, OPT_INNODB_THREAD_SLEEP_DELAY, + OPT_INNODB_ANALYZE_KEY_DIVES, OPT_BDB_CACHE_SIZE, OPT_BDB_LOG_BUFFER_SIZE, OPT_BDB_MAX_LOCK, @@ -5563,6 +5564,10 @@ "Helps to save your data in case the disk image of the database becomes corrupt.", (gptr*) &innobase_force_recovery, (gptr*) &innobase_force_recovery, 0, GET_LONG, REQUIRED_ARG, 0, 0, 6, 0, 1, 0}, + {"innodb_analyze_key_dives", OPT_INNODB_ANALYZE_KEY_DIVES, + "Changes the number of random dives ANALYZE TABLE does on InnoDB tables.", + (gptr*) &srv_analyze_key_dives, (gptr*) &srv_analyze_key_dives, 0, + GET_LONG, REQUIRED_ARG, 8, 8, 1024*1024, 0, 1, 0}, {"innodb_lock_wait_timeout", OPT_INNODB_LOCK_WAIT_TIMEOUT, "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back.", (gptr*) &innobase_lock_wait_timeout, (gptr*) &innobase_lock_wait_timeout, --- ../mysql-5.0.27-orig/./sql/ha_innodb.h 2006-10-20 17:22:53.000000000 -0700 +++ ./sql/ha_innodb.h 2007-01-15 13:58:59.293596616 -0800 @@ -232,6 +232,7 @@ extern ulong srv_thread_concurrency; extern ulong srv_commit_concurrency; extern ulong srv_flush_log_at_trx_commit; +extern ulong srv_analyze_key_dives; } bool innobase_init(void); --- ../mysql-5.0.27-orig/./innobase/include/srv0srv.h 2006-10-20 17:22:52.000000000 -0700 +++ ./innobase/include/srv0srv.h 2007-01-15 13:58:56.013095328 -0800 @@ -263,6 +263,10 @@ /* The server system */ extern srv_sys_t* srv_sys; +/* When estimating number of different kay values in an index sample +this many index pages */ +extern ulong srv_analyze_key_dives; + /* Alternatives for the file flush option in Unix; see the InnoDB manual about what these mean */ #define SRV_UNIX_FDATASYNC 1 /* This is the default; it is currently mapped --- ../mysql-5.0.27-orig/./innobase/btr/btr0cur.c 2006-10-20 17:22:28.000000000 -0700 +++ ./innobase/btr/btr0cur.c 2007-01-15 14:04:12.076046456 -0800 @@ -52,10 +52,6 @@ #define BTR_CUR_PAGE_REORGANIZE_LIMIT (UNIV_PAGE_SIZE / 32) -/* When estimating number of different kay values in an index sample -this many index pages */ -#define BTR_KEY_VAL_ESTIMATE_N_PAGES 8 - /* The structure of a BLOB part header */ /*--------------------------------------*/ #define BTR_BLOB_HDR_PART_LEN 0 /* BLOB part len on this @@ -2857,7 +2853,7 @@ /* We sample some pages in the index to get an estimate */ - for (i = 0; i < BTR_KEY_VAL_ESTIMATE_N_PAGES; i++) { + for (i = 0; i < srv_analyze_key_dives; i++) { rec_t* supremum; mtr_start(&mtr); @@ -2947,7 +2943,7 @@ } /* If we saw k borders between different key values on - BTR_KEY_VAL_ESTIMATE_N_PAGES leaf pages, we can estimate how many + srv_analyze_key_dives leaf pages, we can estimate how many there will be in index->stat_n_leaf_pages */ /* We must take into account that our sample actually represents @@ -2958,25 +2954,25 @@ index->stat_n_diff_key_vals[j] = (n_diff[j] * (ib_longlong)index->stat_n_leaf_pages - + BTR_KEY_VAL_ESTIMATE_N_PAGES - 1 + + srv_analyze_key_dives - 1 + total_external_size + not_empty_flag) - / (BTR_KEY_VAL_ESTIMATE_N_PAGES + / (srv_analyze_key_dives + total_external_size); /* If the tree is small, smaller than < - 10 * BTR_KEY_VAL_ESTIMATE_N_PAGES + total_external_size, then + 10 * srv_analyze_key_dives + total_external_size, then the above estimate is ok. For bigger trees it is common that we do not see any borders between key values in the few pages - we pick. But still there may be BTR_KEY_VAL_ESTIMATE_N_PAGES + we pick. But still there may be srv_analyze_key_dives different key values, or even more. Let us try to approximate that: */ add_on = index->stat_n_leaf_pages / - (10 * (BTR_KEY_VAL_ESTIMATE_N_PAGES + total_external_size)); + (10 * (srv_analyze_key_dives + total_external_size)); - if (add_on > BTR_KEY_VAL_ESTIMATE_N_PAGES) { - add_on = BTR_KEY_VAL_ESTIMATE_N_PAGES; + if (add_on > srv_analyze_key_dives) { + add_on = srv_analyze_key_dives; } index->stat_n_diff_key_vals[j] += add_on; --- ../mysql-5.0.27-orig/./innobase/srv/srv0srv.c 2006-10-20 17:22:28.000000000 -0700 +++ ./innobase/srv/srv0srv.c 2007-01-15 13:59:15.830082688 -0800 @@ -414,6 +414,9 @@ ulint srv_main_thread_process_no = 0; ulint srv_main_thread_id = 0; +/* How many dives to take when estimating statistics */ +ulong srv_analyze_key_dives = 8; + /* IMPLEMENTATION OF THE SERVER MAIN PROGRAM ========================================= --- ../mysql-5.0.27-orig/./libmysqld/set_var.cc 2006-10-20 17:22:39.000000000 -0700 +++ ./libmysqld/set_var.cc 2007-01-15 13:27:50.691667288 -0800 @@ -458,6 +458,8 @@ sys_var_long_ptr sys_innodb_flush_log_at_trx_commit( "innodb_flush_log_at_trx_commit", &srv_flush_log_at_trx_commit); +sys_var_long_ptr sys_innodb_analyze_key_dives("innodb_analyze_key_dives", + &srv_analyze_key_dives); #endif /* Condition pushdown to storage engine */