| 2364 | */ |
| 2365 | |
| 2366 | static int |
| 2367 | alloc_engine_independent_statistics(THD *thd, const TABLE_SHARE *table_share, |
| 2368 | TABLE_STATISTICS_CB *stats_cb) |
| 2369 | { |
| 2370 | Table_statistics *table_stats= stats_cb->table_stats; |
| 2371 | uint fields= table_share->fields; |
| 2372 | uint keys= table_share->keys; |
| 2373 | uint key_parts= table_share->ext_key_parts; |
| 2374 | Index_statistics *index_stats; |
| 2375 | ulonglong *idx_avg_frequency; |
| 2376 | DBUG_ENTER("alloc_engine_independent_statistics"); |
| 2377 | |
| 2378 | Column_statistics *column_stats; |
| 2379 | if (!multi_alloc_root(&stats_cb->mem_root, |
| 2380 | &table_stats, sizeof(Table_statistics), |
| 2381 | &column_stats, sizeof(Column_statistics) * fields, |
| 2382 | &index_stats, sizeof(Index_statistics) * keys, |
| 2383 | &idx_avg_frequency, |
| 2384 | sizeof(*idx_avg_frequency) * key_parts, |
| 2385 | NullS)) |
| 2386 | DBUG_RETURN(1); |
| 2387 | |
| 2388 | /* Zero variables but not the gaps between them */ |
| 2389 | bzero(table_stats, sizeof(Table_statistics)); |
| 2390 | bzero((void*) column_stats, sizeof(Column_statistics) * fields); |
| 2391 | bzero(index_stats, sizeof(Index_statistics) * keys); |
| 2392 | bzero(idx_avg_frequency, sizeof(idx_avg_frequency) * key_parts); |
| 2393 | |
| 2394 | stats_cb->table_stats= table_stats; |
| 2395 | table_stats->columns= table_share->fields; |
| 2396 | table_stats->column_stats= column_stats; |
| 2397 | table_stats->index_stats= index_stats; |
| 2398 | table_stats->idx_avg_frequency= idx_avg_frequency; |
| 2399 | |
| 2400 | create_min_max_statistical_fields(thd, table_share, stats_cb); |
| 2401 | |
| 2402 | for (KEY *key_info= table_share->key_info, *end= key_info + keys; |
| 2403 | key_info < end; |
| 2404 | key_info++, index_stats++) |
| 2405 | { |
| 2406 | index_stats->init_avg_frequency(idx_avg_frequency); |
| 2407 | idx_avg_frequency+= key_info->ext_key_parts; |
| 2408 | } |
| 2409 | DBUG_ASSERT(idx_avg_frequency <= table_stats->idx_avg_frequency + key_parts); |
| 2410 | DBUG_RETURN(0); |
| 2411 | } |
| 2412 | |
| 2413 | |
| 2414 | /** |
no test coverage detected