@@ -214,7 +214,7 @@ class Filesort_tracker : public Sql_alloc
214
214
}
215
215
216
216
/* Functions to get the statistics */
217
- void print_json (Json_writer *writer);
217
+ void print_json_members (Json_writer *writer);
218
218
219
219
ulonglong get_r_loops () { return r_loops; }
220
220
double get_avg_examined_rows ()
@@ -283,6 +283,7 @@ typedef enum
283
283
284
284
typedef enum
285
285
{
286
+ EXPL_ACTION_EOF, /* not-an-action */
286
287
EXPL_ACTION_FILESORT,
287
288
EXPL_ACTION_TEMPTABLE,
288
289
EXPL_ACTION_REMOVE_DUPS,
@@ -329,12 +330,121 @@ typedef enum
329
330
///TODO: handle repeated execution with subselects!
330
331
*/
331
332
333
+ class Sort_and_group_tracker : public Sql_alloc
334
+ {
335
+ enum { MAX_QEP_ACTIONS = 5 };
336
+
337
+ /* Query actions in the order they were made. */
338
+ enum_qep_action qep_actions[MAX_QEP_ACTIONS];
339
+
340
+ /* Number for the next action */
341
+ int cur_action;
342
+
343
+ /*
344
+ Non-zero means there was already an execution which had
345
+ #total_actions actions
346
+ */
347
+ int total_actions;
348
+
349
+ int get_n_actions ()
350
+ {
351
+ return total_actions? total_actions: cur_action;
352
+ }
353
+
354
+ /*
355
+ TRUE<=>there were executions which took different sort/buffer/de-duplicate
356
+ routes. The counter values are not meaningful.
357
+ */
358
+ bool varied_executions;
359
+
360
+ /* Details about query actions */
361
+ union
362
+ {
363
+ Filesort_tracker *filesort_tracker;
364
+ enum_tmp_table_use tmp_table;
365
+ }
366
+ qep_actions_data[MAX_QEP_ACTIONS];
367
+
368
+ Filesort_tracker *dummy_fsort_tracker;
369
+
370
+ public:
371
+ Sort_and_group_tracker () :
372
+ cur_action (0 ), total_actions(0 ), varied_executions(false ),
373
+ dummy_fsort_tracker (NULL )
374
+ {}
375
+
376
+ /* ************** Reporting interface ***************/
377
+ /* Report that join execution is started */
378
+ void report_join_start ()
379
+ {
380
+ if (!total_actions && cur_action != 0 )
381
+ {
382
+ /* This is a second execution */
383
+ total_actions= cur_action;
384
+ }
385
+ cur_action= 0 ;
386
+ }
387
+
388
+ /*
389
+ Report that a temporary table is created. The next step is to write to the
390
+ this tmp. table
391
+ */
392
+ void report_tmp_table (TABLE *tbl);
393
+
394
+ /*
395
+ Report that we are doing a filesort.
396
+ @return
397
+ Tracker object to be used with filesort
398
+ */
399
+ Filesort_tracker *report_sorting ();
400
+
401
+ friend class Iterator ;
402
+ /* ************** Statistics retrieval interface ***************/
403
+ bool had_varied_executions () { return varied_executions; }
404
+
405
+ class Iterator
406
+ {
407
+ Sort_and_group_tracker *owner;
408
+ int idx;
409
+ public:
410
+ Iterator (Sort_and_group_tracker *owner_arg) :
411
+ owner (owner_arg), idx(owner_arg->get_n_actions () - 1)
412
+ {}
413
+
414
+ enum_qep_action get_next (Filesort_tracker **tracker/* ,
415
+ enum_tmp_table_use *tmp_table_use*/ )
416
+ {
417
+ /* Walk back through the array... */
418
+ if (idx < 0 )
419
+ return EXPL_ACTION_EOF;
420
+ switch (owner->qep_actions [idx])
421
+ {
422
+ case EXPL_ACTION_FILESORT:
423
+ *tracker= owner->qep_actions_data [idx].filesort_tracker ;
424
+ break ;
425
+ case EXPL_ACTION_TEMPTABLE:
426
+ // *tmp_table_use= tmp_table_kind[tmp_table_idx++];
427
+ break ;
428
+ default :
429
+ break ;
430
+ }
431
+ return owner->qep_actions [idx--];
432
+ }
433
+
434
+ bool is_last_element () { return idx == -1 ; }
435
+ };
436
+ };
437
+
438
+ #if 0
332
439
class Sort_and_group_tracker : public Sql_alloc
333
440
{
334
441
enum { MAX_QEP_ACTIONS = 5 };
335
442
336
443
/* Query actions in the order they were made */
337
444
enum_qep_action qep_actions[MAX_QEP_ACTIONS];
445
+
446
+ /* Index in filesort_tracker or tmp_table_kind arrays */
447
+ int qep_action_idx[MAX_QEP_ACTIONS];
338
448
uint n_actions;
339
449
340
450
/*
@@ -348,7 +458,7 @@ class Sort_and_group_tracker : public Sql_alloc
348
458
enum_tmp_table_use tmp_table_kind[2];
349
459
int cur_tmp_table;
350
460
351
- friend class Explain_select ;
461
+ // friend class Explain_select;
352
462
353
463
public:
354
464
Sort_and_group_tracker() :
@@ -366,7 +476,10 @@ class Sort_and_group_tracker : public Sql_alloc
366
476
cur_tmp_table= 0;
367
477
}
368
478
369
- /* Report that a temporary table is created. */
479
+ /*
480
+ Report that a temporary table is created. The next step is to write to the
481
+ this tmp. table
482
+ */
370
483
void report_tmp_table(TABLE *tbl)
371
484
{
372
485
DBUG_ASSERT(n_actions < MAX_QEP_ACTIONS);
@@ -385,8 +498,44 @@ class Sort_and_group_tracker : public Sql_alloc
385
498
DBUG_ASSERT(cur_tracker < 2);
386
499
return &filesort_tracker[cur_tracker++];
387
500
}
388
-
501
+
502
+ friend class Iterator;
389
503
/*************** Statistics retrieval interface ***************/
504
+ // need to iterate over steps
505
+ #if 0
506
+ class Iterator
507
+ {
508
+ Sort_and_group_tracker *owner;
509
+ uint idx;
510
+ int fs_tracker_idx;
511
+ //int tmp_table_idx;
512
+ public:
513
+ Iterator(Sort_and_group_tracker *owner_arg) :
514
+ owner(owner_arg), idx(0), fs_tracker_idx(0)//, tmp_table_idx(0)
515
+ {}
516
+
517
+ enum_qep_action get_next(Filesort_tracker **tracker/*,
518
+ enum_tmp_table_use *tmp_table_use*/)
519
+ {
520
+ /* Walk back through the array... */
521
+ if (idx >= owner->n_actions)
522
+ return EXPL_ACTION_EOF;
523
+ switch (owner->qep_actions[idx])
524
+ {
525
+ case EXPL_ACTION_FILESORT:
526
+ *tracker= &owner->filesort_tracker[fs_tracker_idx++];
527
+ break;
528
+ case EXPL_ACTION_TEMPTABLE:
529
+ //*tmp_table_use= tmp_table_kind[tmp_table_idx++];
530
+ break;
531
+ default:
532
+ break;
533
+ }
534
+ return owner->qep_actions[idx++];
535
+ }
536
+ };
537
+ #endif
390
538
//enum_tmp_table_use get_tmp_table_type() { return join_result_tmp_table; }
391
539
};
540
+ #endif
392
541
0 commit comments