230
@@ -1239,8 +1255,20 @@
231
query_length= command_name[thd->command].length;
230
@@ -1240,7 +1256,7 @@
236
+ thd->sent_row_count= thd->examined_row_count= 0;
237
+ thd->sent_row_count= 0;
238
+ thd->bytes_sent_old= thd->status_var.bytes_sent;
239
+ thd->tmp_tables_used= thd->tmp_tables_disk_used= 0;
240
+ thd->tmp_tables_size= 0;
241
+ thd->innodb_was_used= FALSE;
242
+ thd->query_plan_flags= QPLAN_NONE;
243
+ thd->query_plan_fsort_passes= 0;
246
233
for (current_handler= slow_log_handler_list; *current_handler ;)
247
234
- error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
248
235
+ error= (*current_handler++)->log_slow(thd, current_utime, thd->start_time,
249
236
user_host_buff, user_host_len,
250
237
query_utime, lock_utime, is_command,
251
238
query, query_length) || error;
252
@@ -2656,12 +2684,13 @@
239
@@ -2656,12 +2672,13 @@
253
240
TRUE - error occured
523
512
+void increment_thd_innodb_stats(THD* thd,
524
+ unsigned long long trx_id,
527
+ long io_reads_wait_timer,
528
+ long lock_que_wait_timer,
529
+ long que_wait_timer,
513
+ unsigned long long trx_id,
516
+ long io_reads_wait_timer,
517
+ long lock_que_wait_timer,
518
+ long que_wait_timer,
532
+ thd->innodb_was_used = TRUE;
533
+ thd->innodb_trx_id = trx_id;
534
+ thd->innodb_io_reads += io_reads;
535
+ thd->innodb_io_read += io_read;
536
+ thd->innodb_io_reads_wait_timer += io_reads_wait_timer;
537
+ thd->innodb_lock_que_wait_timer += lock_que_wait_timer;
538
+ thd->innodb_innodb_que_wait_timer += que_wait_timer;
539
+ thd->innodb_page_access += page_access;
521
+ thd->innodb_was_used= TRUE;
522
+ thd->innodb_trx_id= trx_id;
523
+ thd->innodb_io_reads+= io_reads;
524
+ thd->innodb_io_read+= io_read;
525
+ thd->innodb_io_reads_wait_timer+= io_reads_wait_timer;
526
+ thd->innodb_lock_que_wait_timer+= lock_que_wait_timer;
527
+ thd->innodb_innodb_que_wait_timer+= que_wait_timer;
528
+ thd->innodb_page_access+= page_access;
562
551
if (!m_internal_handler)
565
@@ -3675,6 +3708,12 @@
554
@@ -1236,6 +1269,8 @@
555
/* Initialize the Debug Sync Facility. See debug_sync.cc. */
556
debug_sync_init_thread(this);
557
#endif /* defined(ENABLED_DEBUG_SYNC) */
559
+ clear_slow_extended();
563
@@ -3682,8 +3717,6 @@
564
backup->in_sub_stmt= in_sub_stmt;
565
backup->enable_slow_log= enable_slow_log;
566
backup->limit_found_rows= limit_found_rows;
567
- backup->examined_row_count= examined_row_count;
568
- backup->sent_row_count= sent_row_count;
569
backup->cuted_fields= cuted_fields;
570
backup->client_capabilities= client_capabilities;
571
backup->savepoints= transaction.savepoints;
572
@@ -3691,6 +3724,7 @@
566
573
first_successful_insert_id_in_prev_stmt;
567
574
backup->first_successful_insert_id_in_cur_stmt=
568
575
first_successful_insert_id_in_cur_stmt;
569
+ backup->innodb_io_reads= innodb_io_reads;
570
+ backup->innodb_io_read= innodb_io_read;
571
+ backup->innodb_io_reads_wait_timer= innodb_io_reads_wait_timer;
572
+ backup->innodb_lock_que_wait_timer= innodb_lock_que_wait_timer;
573
+ backup->innodb_innodb_que_wait_timer= innodb_innodb_que_wait_timer;
574
+ backup->innodb_page_access= innodb_page_access;
576
+ reset_sub_statement_state_slow_extended(backup);
576
578
if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) &&
577
579
!is_current_stmt_binlog_format_row())
578
@@ -3695,6 +3734,14 @@
580
@@ -3706,13 +3740,74 @@
581
/* Disable result sets */
582
client_capabilities &= ~CLIENT_MULTI_RESULTS;
583
in_sub_stmt|= new_state;
584
- examined_row_count= 0;
580
587
transaction.savepoints= 0;
581
588
first_successful_insert_id_in_cur_stmt= 0;
584
+ innodb_io_reads= 0;
586
+ innodb_io_reads_wait_timer= 0;
587
+ innodb_lock_que_wait_timer= 0;
591
+void THD::clear_slow_extended()
593
+ DBUG_ENTER("THD::clear_slow_extended");
595
+ examined_row_count= 0;
596
+ bytes_sent_old= status_var.bytes_sent;
597
+ tmp_tables_used= 0;
598
+ tmp_tables_disk_used= 0;
599
+ tmp_tables_size= 0;
600
+ innodb_was_used= FALSE;
602
+ innodb_io_reads= 0;
604
+ innodb_io_reads_wait_timer= 0;
605
+ innodb_lock_que_wait_timer= 0;
588
606
+ innodb_innodb_que_wait_timer= 0;
589
+ innodb_page_access= 0;
593
@@ -3757,6 +3804,12 @@
607
+ innodb_page_access= 0;
608
+ query_plan_flags= QPLAN_NONE;
609
+ query_plan_fsort_passes= 0;
614
+void THD::reset_sub_statement_state_slow_extended(Sub_statement_state *backup)
616
+ DBUG_ENTER("THD::reset_sub_statement_state_slow_extended");
617
+ backup->sent_row_count= sent_row_count;
618
+ backup->examined_row_count= examined_row_count;
619
+ backup->tmp_tables_used= tmp_tables_used;
620
+ backup->tmp_tables_disk_used= tmp_tables_disk_used;
621
+ backup->tmp_tables_size= tmp_tables_size;
622
+ backup->innodb_was_used= innodb_was_used;
623
+ backup->innodb_io_reads= innodb_io_reads;
624
+ backup->innodb_io_read= innodb_io_read;
625
+ backup->innodb_io_reads_wait_timer= innodb_io_reads_wait_timer;
626
+ backup->innodb_lock_que_wait_timer= innodb_lock_que_wait_timer;
627
+ backup->innodb_innodb_que_wait_timer= innodb_innodb_que_wait_timer;
628
+ backup->innodb_page_access= innodb_page_access;
629
+ backup->query_plan_flags= query_plan_flags;
630
+ backup->query_plan_fsort_passes= query_plan_fsort_passes;
631
+ clear_slow_extended();
635
+void THD::restore_sub_statement_state_slow_extended(const Sub_statement_state *backup)
637
+ DBUG_ENTER("THD::restore_sub_statement_state_slow_extended");
638
+ sent_row_count= backup->sent_row_count;
639
+ examined_row_count+= backup->examined_row_count;
640
+ tmp_tables_used+= backup->tmp_tables_used;
641
+ tmp_tables_disk_used+= backup->tmp_tables_disk_used;
642
+ tmp_tables_size+= backup->tmp_tables_size;
643
+ innodb_was_used= (innodb_was_used || backup->innodb_was_used);
644
+ innodb_io_reads+= backup->innodb_io_reads;
645
+ innodb_io_read+= backup->innodb_io_read;
646
+ innodb_io_reads_wait_timer+= backup->innodb_io_reads_wait_timer;
647
+ innodb_lock_que_wait_timer+= backup->innodb_lock_que_wait_timer;
648
+ innodb_innodb_que_wait_timer+= backup->innodb_innodb_que_wait_timer;
649
+ innodb_page_access+= backup->innodb_page_access;
650
+ query_plan_flags|= backup->query_plan_flags;
651
+ query_plan_fsort_passes+= backup->query_plan_fsort_passes;
655
void THD::restore_sub_statement_state(Sub_statement_state *backup)
657
@@ -3753,7 +3848,6 @@
658
first_successful_insert_id_in_cur_stmt=
659
backup->first_successful_insert_id_in_cur_stmt;
660
limit_found_rows= backup->limit_found_rows;
661
- sent_row_count= backup->sent_row_count;
662
client_capabilities= backup->client_capabilities;
664
If we've left sub-statement mode, reset the fatal error flag.
665
@@ -3771,8 +3865,8 @@
666
The following is added to the old values as we are interested in the
667
total complexity of the query
595
examined_row_count+= backup->examined_row_count;
669
- examined_row_count+= backup->examined_row_count;
596
670
cuted_fields+= backup->cuted_fields;
597
+ innodb_io_reads+= backup->innodb_io_reads;
598
+ innodb_io_read+= backup->innodb_io_read;
599
+ innodb_io_reads_wait_timer+= backup->innodb_io_reads_wait_timer;
600
+ innodb_lock_que_wait_timer+= backup->innodb_lock_que_wait_timer;
601
+ innodb_innodb_que_wait_timer+= backup->innodb_innodb_que_wait_timer;
602
+ innodb_page_access+= backup->innodb_page_access;
671
+ restore_sub_statement_state_slow_extended(backup);
603
672
DBUG_VOID_RETURN;
673
748
+ ulong innodb_innodb_que_wait_timer;
674
749
+ ulong innodb_page_access;
751
+ ulong query_plan_flags;
752
+ ulong query_plan_fsort_passes;
753
+ /*** The variables above used in slow_extended.patch ***/
676
755
SAVEPOINT *savepoints;
677
756
enum enum_check_fields count_cuted_fields;
679
@@ -1588,6 +1638,26 @@
758
@@ -1588,6 +1648,71 @@
680
759
thr_lock_type update_lock_default;
681
760
Delayed_insert *di;
762
+ /*** Following variables used in slow_extended.patch ***/
764
+ Variable write_to_slow_log:
766
+ * sql_connect.cc (log_slow_rate_limit support)
767
+ * slave.cc (log_slow_slave_statements support)
768
+ 2) The variable is initialized on the thread startup and remains
769
+ constant afterwards. This will change when
770
+ LP #712396 ("log_slow_slave_statements not work on replication
771
+ threads without RESTART") is implemented.
772
+ 3) An implementation of LP #688646 ("Make query sampling possible by query") should use it.
683
774
+ bool write_to_slow_log;
776
+ Variable bytes_send_old saves value of thd->status_var.bytes_sent
777
+ before query execution.
685
779
+ ulonglong bytes_sent_old;
781
+ Variables tmp_tables_*** collect statistics about usage of temporary tables
686
783
+ ulong tmp_tables_used;
687
784
+ ulong tmp_tables_disk_used;
688
785
+ ulonglong tmp_tables_size;
787
+ Variable innodb_was_used shows used or not InnoDB engine in current query.
689
789
+ bool innodb_was_used;
791
+ Following Variables innodb_*** (is |should be) different from
792
+ default values only if (innodb_was_used==TRUE)
690
794
+ ulonglong innodb_trx_id;
691
795
+ ulong innodb_io_reads;
692
796
+ ulonglong innodb_io_read;
695
799
+ ulong innodb_innodb_que_wait_timer;
696
800
+ ulong innodb_page_access;
803
+ Variable query_plan_flags collects information about query plan entites
804
+ used on query execution.
698
806
+ ulong query_plan_flags;
808
+ Variable query_plan_fsort_passes collects information about file sort passes
809
+ acquired during query execution.
699
811
+ ulong query_plan_fsort_passes;
813
+ Query can generate several errors/warnings during execution
814
+ (see THD::handle_condition comment in sql_class.h)
815
+ Variable last_errno contains the last error/warning acquired during
701
818
+ uint last_errno;
819
+ /*** The variables above used in slow_extended.patch ***/
821
+ /*** Following methods used in slow_extended.patch ***/
822
+ void clear_slow_extended();
823
+ void reset_sub_statement_state_slow_extended(Sub_statement_state *backup);
824
+ void restore_sub_statement_state_slow_extended(const Sub_statement_state *backup);
825
+ /*** The methods above used in slow_extended.patch ***/
703
827
/* <> 0 if we are inside of trigger or stored function. */
704
828
uint in_sub_stmt;
842
974
thd_proc_info(thd, "logging slow query");
844
976
if (((thd->server_status & SERVER_QUERY_WAS_SLOW) ||
845
@@ -1879,6 +1969,9 @@
846
context.resolve_in_table_list_only(select_lex->
849
+ /* Reset the counter at all cases for the extended slow query log */
850
+ thd->sent_row_count= 0;
853
Reset warning count for each query that uses tables
854
A better approach would be to reset this for any commands
855
@@ -5303,6 +5396,21 @@
977
@@ -5301,7 +5392,8 @@
978
thd->stmt_da->reset_diagnostics_area();
979
thd->warning_info->reset_for_next_command();
856
980
thd->rand_used= 0;
857
thd->sent_row_count= thd->examined_row_count= 0;
981
- thd->sent_row_count= thd->examined_row_count= 0;
983
+ thd->clear_slow_extended();
859
+ thd->bytes_sent_old= thd->status_var.bytes_sent;
860
+ thd->tmp_tables_used= thd->tmp_tables_disk_used= 0;
861
+ thd->tmp_tables_size= 0;
862
+ thd->innodb_was_used= FALSE;
863
+ thd->innodb_trx_id= 0;
864
+ thd->innodb_io_reads= 0;
865
+ thd->innodb_io_read= 0;
866
+ thd->innodb_io_reads_wait_timer= 0;
867
+ thd->innodb_lock_que_wait_timer= 0;
868
+ thd->innodb_innodb_que_wait_timer= 0;
869
+ thd->innodb_page_access= 0;
870
+ thd->query_plan_flags= QPLAN_NONE;
871
+ thd->query_plan_fsort_passes= 0;
872
+ thd->last_errno= 0;
874
985
thd->reset_current_stmt_binlog_format_row();
875
986
thd->binlog_unsafe_warning_flags= 0;
877
987
--- a/sql/sql_select.cc
878
988
+++ b/sql/sql_select.cc
879
989
@@ -6902,7 +6902,10 @@