~percona-dev/percona-xtradb/fix-bug547230-bug548442

« back to all changes in this revision

Viewing changes to innodb_stats.patch

  • Committer: kinoyasu
  • Date: 2010-03-26 10:01:13 UTC
  • Revision ID: kinoyasu@gauntlet3-20100326100113-bn1e7cakwtnf5je4
fix bug547230 and bug548442

Show diffs side-by-side

added added

removed removed

Lines of Context:
425
425
diff -ruN innodb_plugin-1.0.6_orig/handler/ha_innodb.cc innodb_plugin-1.0.6_tmp/handler/ha_innodb.cc
426
426
--- innodb_plugin-1.0.6_orig/handler/ha_innodb.cc       2009-12-04 12:15:57.000000000 +0900
427
427
+++ innodb_plugin-1.0.6_tmp/handler/ha_innodb.cc        2009-12-04 12:16:38.000000000 +0900
428
 
@@ -7312,7 +7312,9 @@
 
428
@@ -4644,6 +4644,10 @@
 
429
 
 
430
        error = row_insert_for_mysql((byte*) record, prebuilt);
 
431
 
 
432
+#ifdef EXTENDED_FOR_USERSTAT
 
433
+       if (error == DB_SUCCESS) rows_changed++;
 
434
+#endif
 
435
+
 
436
        /* Handle duplicate key errors */
 
437
        if (auto_inc_used) {
 
438
                ulint           err;
 
439
@@ -4975,6 +4979,10 @@
 
440
                }
 
441
        }
 
442
 
 
443
+#ifdef EXTENDED_FOR_USERSTAT
 
444
+       if (error == DB_SUCCESS) rows_changed++;
 
445
+#endif
 
446
+
 
447
        innodb_srv_conc_exit_innodb(trx);
 
448
 
 
449
        error = convert_error_code_to_mysql(error,
 
450
@@ -5028,6 +5036,10 @@
 
451
 
 
452
        error = row_update_for_mysql((byte*) record, prebuilt);
 
453
 
 
454
+#ifdef EXTENDED_FOR_USERSTAT
 
455
+       if (error == DB_SUCCESS) rows_changed++;
 
456
+#endif
 
457
+
 
458
        innodb_srv_conc_exit_innodb(trx);
 
459
 
 
460
        error = convert_error_code_to_mysql(
 
461
@@ -5536,6 +5548,11 @@
 
462
        case DB_SUCCESS:
 
463
                error = 0;
 
464
                table->status = 0;
 
465
+#ifdef EXTENDED_FOR_USERSTAT
 
466
+               rows_read++;
 
467
+               if (active_index >= 0 && active_index < MAX_KEY)
 
468
+                       index_rows_read[active_index]++;
 
469
+#endif
 
470
                break;
 
471
        case DB_RECORD_NOT_FOUND:
 
472
                error = HA_ERR_END_OF_FILE;
 
473
@@ -7312,7 +7329,9 @@
429
474
        ib_table = prebuilt->table;
430
475
 
431
476
        if (flag & HA_STATUS_TIME) {
436
481
                        /* In sql_show we call with this flag: update
437
482
                        then statistics so that they are up-to-date */
438
483
 
439
 
@@ -7394,7 +7396,7 @@
 
484
@@ -7394,7 +7413,7 @@
440
485
                We do not update delete_length if no locking is requested
441
486
                so the "old" value can remain. delete_length is initialized
442
487
                to 0 in the ha_statistics' constructor. */
445
490
 
446
491
                        /* lock the data dictionary to avoid races with
447
492
                        ibd_file_missing and tablespace_discarded */
448
 
@@ -10274,6 +10276,37 @@
 
493
@@ -10274,6 +10293,37 @@
449
494
   "The number of index pages to sample when calculating statistics (default 8)",
450
495
   NULL, NULL, 8, 1, ~0ULL, 0);
451
496
 
483
528
 static MYSQL_SYSVAR_BOOL(adaptive_hash_index, btr_search_enabled,
484
529
   PLUGIN_VAR_OPCMDARG,
485
530
   "Enable InnoDB adaptive hash index (enabled by default).  "
486
 
@@ -10583,6 +10616,9 @@
 
531
@@ -10583,6 +10633,9 @@
487
532
   MYSQL_SYSVAR(overwrite_relay_log_info),
488
533
   MYSQL_SYSVAR(rollback_on_timeout),
489
534
   MYSQL_SYSVAR(stats_on_metadata),
493
538
   MYSQL_SYSVAR(stats_sample_pages),
494
539
   MYSQL_SYSVAR(adaptive_hash_index),
495
540
   MYSQL_SYSVAR(replication_delay),
496
 
@@ -10643,6 +10679,8 @@
 
541
@@ -10643,6 +10696,8 @@
497
542
 i_s_innodb_cmp_reset,
498
543
 i_s_innodb_cmpmem,
499
544
 i_s_innodb_cmpmem_reset,
513
558
 /* from buf0buf.c */
514
559
 struct buf_chunk_struct{
515
560
        ulint           mem_size;       /* allocated size of the chunk */
516
 
@@ -2657,3 +2658,299 @@
 
561
@@ -2657,3 +2658,342 @@
517
562
        /* void* */
518
563
        STRUCT_FLD(__reserved1, NULL)
519
564
 };
522
567
+*/
523
568
+static ST_FIELD_INFO   i_s_innodb_table_stats_info[] =
524
569
+{
 
570
+       {STRUCT_FLD(field_name,         "table_schema"),
 
571
+        STRUCT_FLD(field_length,       NAME_LEN),
 
572
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
 
573
+        STRUCT_FLD(value,              0),
 
574
+        STRUCT_FLD(field_flags,        0),
 
575
+        STRUCT_FLD(old_name,           ""),
 
576
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
 
577
+
525
578
+       {STRUCT_FLD(field_name,         "table_name"),
526
579
+        STRUCT_FLD(field_length,       NAME_LEN),
527
580
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
567
620
+
568
621
+static ST_FIELD_INFO   i_s_innodb_index_stats_info[] =
569
622
+{
 
623
+       {STRUCT_FLD(field_name,         "table_schema"),
 
624
+        STRUCT_FLD(field_length,       NAME_LEN),
 
625
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
 
626
+        STRUCT_FLD(value,              0),
 
627
+        STRUCT_FLD(field_flags,        0),
 
628
+        STRUCT_FLD(old_name,           ""),
 
629
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
 
630
+
570
631
+       {STRUCT_FLD(field_name,         "table_name"),
571
632
+        STRUCT_FLD(field_length,       NAME_LEN),
572
633
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
642
703
+       table = UT_LIST_GET_FIRST(dict_sys->table_LRU);
643
704
+
644
705
+       while (table) {
 
706
+               char    buf[NAME_LEN * 2 + 2];
 
707
+               char*   ptr;
 
708
+
645
709
+               if (table->stat_clustered_index_size == 0) {
646
710
+                       table = UT_LIST_GET_NEXT(table_LRU, table);
647
711
+                       continue;
648
712
+               }
649
713
+
650
 
+               field_store_string(i_s_table->field[0], table->name);
651
 
+               i_s_table->field[1]->store(table->stat_n_rows);
652
 
+               i_s_table->field[2]->store(table->stat_clustered_index_size);
653
 
+               i_s_table->field[3]->store(table->stat_sum_of_other_index_sizes);
654
 
+               i_s_table->field[4]->store(table->stat_modified_counter);
 
714
+               buf[NAME_LEN * 2 + 1] = 0;
 
715
+               strncpy(buf, table->name, NAME_LEN * 2 + 1);
 
716
+               ptr = strchr(buf, '/');
 
717
+               if (ptr) {
 
718
+                       *ptr = '\0';
 
719
+                       ++ptr;
 
720
+               } else {
 
721
+                       ptr = buf;
 
722
+               }
 
723
+
 
724
+               field_store_string(i_s_table->field[0], buf);
 
725
+               field_store_string(i_s_table->field[1], ptr);
 
726
+               i_s_table->field[2]->store(table->stat_n_rows);
 
727
+               i_s_table->field[3]->store(table->stat_clustered_index_size);
 
728
+               i_s_table->field[4]->store(table->stat_sum_of_other_index_sizes);
 
729
+               i_s_table->field[5]->store(table->stat_modified_counter);
655
730
+
656
731
+               if (schema_table_store_record(thd, i_s_table)) {
657
732
+                       status = 1;
707
782
+               while (index) {
708
783
+                       char    buff[256+1];
709
784
+                       char    row_per_keys[256+1];
 
785
+                       char    buf[NAME_LEN * 2 + 2];
 
786
+                       char*   ptr;
710
787
+                       ulint   i;
711
788
+
712
 
+                       field_store_string(i_s_table->field[0], table->name);
713
 
+                       field_store_string(i_s_table->field[1], index->name);
714
 
+                       i_s_table->field[2]->store(index->n_uniq);
 
789
+                       buf[NAME_LEN * 2 + 1] = 0;
 
790
+                       strncpy(buf, table->name, NAME_LEN * 2 + 1);
 
791
+                       ptr = strchr(buf, '/');
 
792
+                       if (ptr) {
 
793
+                               *ptr = '\0';
 
794
+                               ++ptr;
 
795
+                       } else {
 
796
+                               ptr = buf;
 
797
+                       }
 
798
+
 
799
+                       field_store_string(i_s_table->field[0], buf);
 
800
+                       field_store_string(i_s_table->field[1], ptr);
 
801
+                       field_store_string(i_s_table->field[2], index->name);
 
802
+                       i_s_table->field[3]->store(index->n_uniq);
715
803
+
716
804
+                       row_per_keys[0] = '\0';
717
805
+                       if (index->stat_n_diff_key_vals) {
727
815
+                                       strncat(row_per_keys, buff, 256 - strlen(row_per_keys));
728
816
+                               }
729
817
+                       }
730
 
+                       field_store_string(i_s_table->field[3], row_per_keys);
 
818
+                       field_store_string(i_s_table->field[4], row_per_keys);
731
819
+
732
 
+                       i_s_table->field[4]->store(index->stat_index_size);
733
 
+                       i_s_table->field[5]->store(index->stat_n_leaf_pages);
 
820
+                       i_s_table->field[5]->store(index->stat_index_size);
 
821
+                       i_s_table->field[6]->store(index->stat_n_leaf_pages);
734
822
+
735
823
+                       if (schema_table_store_record(thd, i_s_table)) {
736
824
+                               status = 1;