@@ -7708,39 +7708,6 @@ bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array,
7708
7708
DBUG_RETURN (MY_TEST (thd->is_error ()));
7709
7709
}
7710
7710
7711
- /*
7712
- make list of leaves for a single TABLE_LIST
7713
-
7714
- SYNOPSIS
7715
- make_leaves_for_single_table()
7716
- thd Thread handler
7717
- leaves List of leaf tables to be filled
7718
- table TABLE_LIST object to process
7719
- full_table_list Whether to include tables from mergeable derived table/view
7720
- */
7721
- void make_leaves_for_single_table (THD *thd, List<TABLE_LIST> &leaves,
7722
- TABLE_LIST *table, bool & full_table_list,
7723
- TABLE_LIST *boundary)
7724
- {
7725
- if (table == boundary)
7726
- full_table_list= !full_table_list;
7727
- if (full_table_list && table->is_merged_derived ())
7728
- {
7729
- SELECT_LEX *select_lex= table->get_single_select ();
7730
- /*
7731
- It's safe to use select_lex->leaf_tables because all derived
7732
- tables/views were already prepared and has their leaf_tables
7733
- set properly.
7734
- */
7735
- make_leaves_list (thd, leaves, select_lex->get_table_list (),
7736
- full_table_list, boundary);
7737
- }
7738
- else
7739
- {
7740
- leaves.push_back (table, thd->mem_root );
7741
- }
7742
- }
7743
-
7744
7711
7745
7712
/*
7746
7713
Perform checks like all given fields exists, if exists fill struct with
@@ -7767,79 +7734,40 @@ int setup_returning_fields(THD* thd, TABLE_LIST* table_list)
7767
7734
7768
7735
SYNOPSIS
7769
7736
make_leaves_list()
7770
- leaves List of leaf tables to be filled
7771
- tables Table list
7772
- full_table_list Whether to include tables from mergeable derived table/view.
7773
- We need them for checks for INSERT/UPDATE statements only.
7737
+ list pointer to pointer on list first element
7738
+ tables table list
7739
+ full_table_list whether to include tables from mergeable derived table/view.
7740
+ we need them for checks for INSERT/UPDATE statements only.
7741
+
7742
+ RETURN pointer on pointer to next_leaf of last element
7774
7743
*/
7775
7744
7776
- void make_leaves_list (THD *thd, List<TABLE_LIST> &leaves , TABLE_LIST *tables,
7745
+ void make_leaves_list (THD *thd, List<TABLE_LIST> &list , TABLE_LIST *tables,
7777
7746
bool full_table_list, TABLE_LIST *boundary)
7778
7747
7779
7748
{
7780
7749
for (TABLE_LIST *table= tables; table; table= table->next_local )
7781
7750
{
7782
- make_leaves_for_single_table (thd, leaves, table, full_table_list,
7783
- boundary);
7784
- }
7785
- }
7786
-
7787
-
7788
- /*
7789
- Setup the map and other attributes for a single TABLE_LIST object
7790
-
7791
- SYNOPSIS
7792
- setup_table_attributes()
7793
- thd Thread handler
7794
- table_list TABLE_LIST object to process
7795
- first_select_table First table participating in SELECT for INSERT..SELECT
7796
- statements, NULL for other cases
7797
- tablenr Serial number of the table in the SQL statement
7798
-
7799
- RETURN
7800
- false Success
7801
- true Failure
7802
- */
7803
- bool setup_table_attributes (THD *thd, TABLE_LIST *table_list,
7804
- TABLE_LIST *first_select_table,
7805
- uint &tablenr)
7806
- {
7807
- TABLE *table= table_list->table ;
7808
- if (table)
7809
- table->pos_in_table_list = table_list;
7810
- if (first_select_table && table_list->top_table () == first_select_table)
7811
- {
7812
- /* new counting for SELECT of INSERT ... SELECT command */
7813
- first_select_table= 0 ;
7814
- thd->lex ->first_select_lex ()->insert_tables = tablenr;
7815
- tablenr= 0 ;
7816
- }
7817
- if (table_list->jtbm_subselect )
7818
- {
7819
- table_list->jtbm_table_no = tablenr;
7820
- }
7821
- else if (table)
7822
- {
7823
- table->pos_in_table_list = table_list;
7824
- setup_table_map (table, table_list, tablenr);
7825
-
7826
- if (table_list->process_index_hints (table))
7827
- return true ;
7828
- }
7829
- tablenr++;
7830
- /*
7831
- We test the max tables here as we setup_table_map() should not be called
7832
- with tablenr >= 64
7833
- */
7834
- if (tablenr > MAX_TABLES)
7835
- {
7836
- my_error (ER_TOO_MANY_TABLES, MYF (0 ), static_cast <int >(MAX_TABLES));
7837
- return true ;
7751
+ if (table == boundary)
7752
+ full_table_list= !full_table_list;
7753
+ if (full_table_list && table->is_merged_derived ())
7754
+ {
7755
+ SELECT_LEX *select_lex= table->get_single_select ();
7756
+ /*
7757
+ It's safe to use select_lex->leaf_tables because all derived
7758
+ tables/views were already prepared and has their leaf_tables
7759
+ set properly.
7760
+ */
7761
+ make_leaves_list (thd, list, select_lex->get_table_list (),
7762
+ full_table_list, boundary);
7763
+ }
7764
+ else
7765
+ {
7766
+ list.push_back (table, thd->mem_root );
7767
+ }
7838
7768
}
7839
- return false ;
7840
7769
}
7841
7770
7842
-
7843
7771
/*
7844
7772
prepare tables
7845
7773
@@ -7896,14 +7824,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
7896
7824
leaves.empty ();
7897
7825
if (select_lex->prep_leaf_list_state != SELECT_LEX::SAVED)
7898
7826
{
7899
- /*
7900
- For INSERT ... SELECT statements we must not include the first table
7901
- (where the data is being inserted into) in the list of leaves
7902
- */
7903
- TABLE_LIST *tables_for_leaves=
7904
- select_insert ? first_select_table : tables;
7905
- make_leaves_list (thd, leaves, tables_for_leaves, full_table_list,
7906
- first_select_table);
7827
+ make_leaves_list (thd, leaves, tables, full_table_list, first_select_table);
7907
7828
select_lex->prep_leaf_list_state = SELECT_LEX::READY;
7908
7829
select_lex->leaf_tables_exec .empty ();
7909
7830
}
@@ -7914,34 +7835,37 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
7914
7835
leaves.push_back (table_list, thd->mem_root );
7915
7836
}
7916
7837
7917
- List_iterator<TABLE_LIST> ti (leaves);
7918
7838
while ((table_list= ti++))
7919
7839
{
7920
- if (setup_table_attributes (thd, table_list, first_select_table, tablenr))
7921
- DBUG_RETURN (1 );
7922
- }
7923
-
7924
- if (select_insert)
7925
- {
7926
- /*
7927
- The table/view in which the data is inserted must not be included into
7928
- the leaf_tables list. But we need this table/view to setup attributes
7929
- for it. So build a temporary list of leaves and setup attributes for
7930
- the tables included
7931
- */
7932
- List<TABLE_LIST> leaves;
7933
- TABLE_LIST *table= tables;
7934
-
7935
- make_leaves_for_single_table (thd, leaves, table, full_table_list,
7936
- first_select_table);
7937
-
7938
- List_iterator<TABLE_LIST> ti (leaves);
7939
- while ((table_list= ti++))
7840
+ TABLE *table= table_list->table ;
7841
+ if (table)
7842
+ table->pos_in_table_list = table_list;
7843
+ if (first_select_table &&
7844
+ table_list->top_table () == first_select_table)
7940
7845
{
7941
- if (setup_table_attributes (thd, table_list, first_select_table,
7942
- tablenr))
7846
+ /* new counting for SELECT of INSERT ... SELECT command */
7847
+ first_select_table= 0 ;
7848
+ thd->lex ->select_lex .insert_tables = tablenr;
7849
+ tablenr= 0 ;
7850
+ }
7851
+ if (table_list->jtbm_subselect )
7852
+ {
7853
+ table_list->jtbm_table_no = tablenr;
7854
+ }
7855
+ else if (table)
7856
+ {
7857
+ table->pos_in_table_list = table_list;
7858
+ setup_table_map (table, table_list, tablenr);
7859
+
7860
+ if (table_list->process_index_hints (table))
7943
7861
DBUG_RETURN (1 );
7944
7862
}
7863
+ tablenr++;
7864
+ }
7865
+ if (tablenr > MAX_TABLES)
7866
+ {
7867
+ my_error (ER_TOO_MANY_TABLES,MYF (0 ), static_cast <int >(MAX_TABLES));
7868
+ DBUG_RETURN (1 );
7945
7869
}
7946
7870
}
7947
7871
else
0 commit comments