@@ -559,14 +559,16 @@ static void filter_gcol_for_dynamic_range_scan(QEP_TAB *const tab)
559
559
560
560
void JOIN_CACHE::filter_virtual_gcol_base_cols ()
561
561
{
562
+ DBUG_ASSERT (save_read_set_for_gcol.size () == 0 );
562
563
for (QEP_TAB *tab= qep_tab - tables; tab < qep_tab; tab++)
563
564
{
564
565
TABLE *table= tab->table ();
565
566
if (table->vfield == NULL )
566
567
continue ;
567
568
568
569
const uint index = tab->effective_index ();
569
- if (index != MAX_KEY && table->index_contains_some_virtual_gcol (index ) &&
570
+ const bool cov_index =
571
+ index != MAX_KEY && table->index_contains_some_virtual_gcol (index ) &&
570
572
/*
571
573
There are two cases:
572
574
- If the table scan uses covering index scan, we can get the value
@@ -576,24 +578,40 @@ void JOIN_CACHE::filter_virtual_gcol_base_cols()
576
578
After restore the base columns, the value of virtual generated
577
579
columns can be calculated correctly.
578
580
*/
579
- table->covering_keys .is_set (index ))
581
+ table->covering_keys .is_set (index );
582
+
583
+ if (!(cov_index || tab->dynamic_range ())) continue ;
584
+
585
+ /*
586
+ Save of a copy of table->read_set in save_read_set so that it can be
587
+ restored. tmp_set cannot be used as recipient for this as it's already
588
+ used in other parts of JOIN_CACHE::init().
589
+ */
590
+ my_bitmap_map *bitbuf =
591
+ (my_bitmap_map *)alloc_root (tab->table ()->in_use ->mem_root ,
592
+ table->s ->column_bitmap_size );
593
+ MY_BITMAP *save_read_set =
594
+ (MY_BITMAP *)alloc_root (tab->table ()->in_use ->mem_root ,
595
+ sizeof (MY_BITMAP));
596
+ bitmap_init (save_read_set, bitbuf, table->s ->fields , false );
597
+ bitmap_copy (save_read_set, table->read_set );
598
+ /*
599
+ restore_virtual_gcol_base_cols() will need old bitmap so we save a
600
+ reference to it.
601
+ */
602
+ save_read_set_for_gcol.push_back (save_read_set);
603
+
604
+ if (cov_index)
580
605
{
581
- DBUG_ASSERT (bitmap_is_clear_all (&table->tmp_set ));
582
- // Keep table->read_set in tmp_set so that it can be restored
583
- bitmap_copy (&table->tmp_set , table->read_set );
584
606
bitmap_clear_all (table->read_set );
585
607
table->mark_columns_used_by_index_no_reset (index , table->read_set );
586
608
if (table->s ->primary_key != MAX_KEY)
587
609
table->mark_columns_used_by_index_no_reset (table->s ->primary_key ,
588
610
table->read_set );
589
- bitmap_intersect (table->read_set , &table-> tmp_set );
611
+ bitmap_intersect (table->read_set , save_read_set );
590
612
}
591
613
else if (tab->dynamic_range ())
592
614
{
593
- DBUG_ASSERT (bitmap_is_clear_all (&table->tmp_set ));
594
- // Keep table->read_set in tmp_set so that it can be restored
595
- bitmap_copy (&table->tmp_set , table->read_set );
596
-
597
615
filter_gcol_for_dynamic_range_scan (tab);
598
616
}
599
617
}
@@ -607,18 +625,26 @@ void JOIN_CACHE::filter_virtual_gcol_base_cols()
607
625
608
626
void JOIN_CACHE::restore_virtual_gcol_base_cols ()
609
627
{
628
+ MY_BITMAP **save_read_set= save_read_set_for_gcol.begin ();
629
+
610
630
for (QEP_TAB *tab= qep_tab - tables; tab < qep_tab; tab++)
611
631
{
612
632
TABLE *table= tab->table ();
613
633
if (table->vfield == NULL )
614
634
continue ;
615
635
616
- if (!bitmap_is_clear_all (&table->tmp_set ))
617
- {
618
- bitmap_copy (table->read_set , &table->tmp_set );
619
- bitmap_clear_all (&table->tmp_set );
620
- }
636
+ const uint index = tab->effective_index ();
637
+ const bool cov_index =
638
+ (index != MAX_KEY && table->index_contains_some_virtual_gcol (index ) &&
639
+ table->covering_keys .is_set (index ));
640
+
641
+ if (!(cov_index || tab->dynamic_range ())) continue ;
642
+
643
+ DBUG_ASSERT (!bitmap_is_clear_all (*save_read_set));
644
+ bitmap_copy (table->read_set , *save_read_set);
645
+ save_read_set++;
621
646
}
647
+ DBUG_ASSERT (save_read_set == save_read_set_for_gcol.end ());
622
648
}
623
649
624
650
/*
0 commit comments