@@ -823,196 +823,196 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
823
823
824
824
for (table= tables; table; table= table->next_local)
825
825
{
826
- if (table->table && table->table->versioned())
827
- {
828
- vers_select_conds_t &vers_conditions= table->vers_conditions;
826
+ if (!table->table || !table->table->versioned())
827
+ continue;
829
828
830
- // propagate system_time from nearest outer SELECT_LEX
831
- if (!vers_conditions && outer_slex && vers_import_outer)
832
- {
833
- TABLE_LIST* derived= master_unit()->derived;
834
- // inner SELECT may not be a derived table (derived == NULL)
835
- while (derived && outer_slex && (!derived->vers_conditions || derived->vers_conditions.from_inner))
836
- {
837
- derived= outer_slex->master_unit()->derived;
838
- outer_slex= outer_slex->next_select_in_list();
839
- }
840
- if (derived && outer_slex && !derived->vers_conditions.from_inner)
841
- {
842
- DBUG_ASSERT(derived->vers_conditions);
843
- vers_conditions= derived->vers_conditions;
844
- }
845
- }
829
+ vers_select_conds_t &vers_conditions= table->vers_conditions;
846
830
847
- // propagate system_time from sysvar
848
- if (!vers_conditions)
831
+ // propagate system_time from nearest outer SELECT_LEX
832
+ if (!vers_conditions && outer_slex && vers_import_outer)
833
+ {
834
+ TABLE_LIST* derived= master_unit()->derived;
835
+ // inner SELECT may not be a derived table (derived == NULL)
836
+ while (derived && outer_slex && (!derived->vers_conditions || derived->vers_conditions.from_inner))
849
837
{
850
- if (vers_conditions.init_from_sysvar(thd))
851
- DBUG_RETURN(-1 );
838
+ derived= outer_slex->master_unit()->derived;
839
+ outer_slex= outer_slex->next_select_in_list( );
852
840
}
853
-
854
- if (vers_conditions)
841
+ if (derived && outer_slex && !derived->vers_conditions.from_inner)
855
842
{
856
- switch (this->lock_type)
857
- {
858
- case TL_WRITE_ALLOW_WRITE:
859
- case TL_WRITE_CONCURRENT_INSERT:
860
- case TL_WRITE_DELAYED:
861
- case TL_WRITE_DEFAULT:
862
- case TL_WRITE_LOW_PRIORITY:
863
- case TL_WRITE:
864
- case TL_WRITE_ONLY:
865
- my_error(ER_VERS_HISTORY_LOCK, MYF(0));
866
- DBUG_RETURN(-1);
867
- default:
868
- break;
869
- }
843
+ DBUG_ASSERT(derived->vers_conditions);
844
+ vers_conditions= derived->vers_conditions;
845
+ }
846
+ }
870
847
871
- if (vers_conditions == FOR_SYSTEM_TIME_ALL)
872
- continue;
873
- } // if (vers_conditions)
848
+ // propagate system_time from sysvar
849
+ if (!vers_conditions)
850
+ {
851
+ if (vers_conditions.init_from_sysvar(thd))
852
+ DBUG_RETURN(-1);
853
+ }
874
854
875
- if (table->on_expr)
855
+ if (vers_conditions)
856
+ {
857
+ switch (this->lock_type)
876
858
{
877
- dst_cond= &table->on_expr;
859
+ case TL_WRITE_ALLOW_WRITE:
860
+ case TL_WRITE_CONCURRENT_INSERT:
861
+ case TL_WRITE_DELAYED:
862
+ case TL_WRITE_DEFAULT:
863
+ case TL_WRITE_LOW_PRIORITY:
864
+ case TL_WRITE:
865
+ case TL_WRITE_ONLY:
866
+ my_error(ER_VERS_HISTORY_LOCK, MYF(0));
867
+ DBUG_RETURN(-1);
868
+ default:
869
+ break;
878
870
}
879
871
880
- if (TABLE_LIST *t= table->embedding)
881
- {
882
- if (t->on_expr)
883
- dst_cond= &t->on_expr;
884
- }
872
+ if (vers_conditions == FOR_SYSTEM_TIME_ALL)
873
+ continue;
874
+ } // if (vers_conditions)
885
875
886
- const LEX_CSTRING *fstart= &table->table->vers_start_field()->field_name;
887
- const LEX_CSTRING *fend= &table->table->vers_end_field()->field_name;
876
+ if (table->on_expr)
877
+ {
878
+ dst_cond= &table->on_expr;
879
+ }
888
880
889
- Item *row_start=
890
- newx Item_field(thd, &this->context, table->db, table->alias, fstart);
891
- Item *row_end=
892
- newx Item_field(thd, &this->context, table->db, table->alias, fend);
881
+ if (TABLE_LIST *t= table->embedding)
882
+ {
883
+ if (t->on_expr)
884
+ dst_cond= &t->on_expr;
885
+ }
886
+
887
+ const LEX_CSTRING *fstart= &table->table->vers_start_field()->field_name;
888
+ const LEX_CSTRING *fend= &table->table->vers_end_field()->field_name;
889
+
890
+ Item *row_start=
891
+ newx Item_field(thd, &this->context, table->db, table->alias, fstart);
892
+ Item *row_end=
893
+ newx Item_field(thd, &this->context, table->db, table->alias, fend);
893
894
894
- bool tmp_from_ib=
895
- table->table->s->table_category == TABLE_CATEGORY_TEMPORARY &&
896
- table->table->vers_start_field()->type() == MYSQL_TYPE_LONGLONG;
897
- bool timestamps_only= table->table->versioned_by_sql() && !tmp_from_ib;
895
+ bool tmp_from_ib=
896
+ table->table->s->table_category == TABLE_CATEGORY_TEMPORARY &&
897
+ table->table->vers_start_field()->type() == MYSQL_TYPE_LONGLONG;
898
+ bool timestamps_only= table->table->versioned_by_sql() && !tmp_from_ib;
898
899
899
- if (vers_conditions)
900
+ if (vers_conditions)
901
+ {
902
+ vers_conditions.resolve_units(timestamps_only);
903
+ if (timestamps_only && (vers_conditions.unit_start == UNIT_TRX_ID ||
904
+ vers_conditions.unit_end == UNIT_TRX_ID))
900
905
{
901
- vers_conditions.resolve_units(timestamps_only);
902
- if (timestamps_only && (vers_conditions.unit_start == UNIT_TRX_ID ||
903
- vers_conditions.unit_end == UNIT_TRX_ID))
904
- {
905
- my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name);
906
- DBUG_RETURN(-1);
907
- }
906
+ my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name);
907
+ DBUG_RETURN(-1);
908
908
}
909
+ }
909
910
910
- Item *cond1= 0, *cond2= 0, *curr= 0;
911
- // Temporary tables of can be created from INNODB tables and thus will
912
- // have uint64 type of sys_trx_(start|end) field.
913
- // They need special handling.
914
- TABLE *t= table->table;
915
- if (tmp_from_ib || t->versioned_by_sql() ||
916
- thd->variables.vers_innodb_algorithm_simple)
911
+ Item *cond1= 0, *cond2= 0, *curr= 0;
912
+ // Temporary tables of can be created from INNODB tables and thus will
913
+ // have uint64 type of sys_trx_(start|end) field.
914
+ // They need special handling.
915
+ TABLE *t= table->table;
916
+ if (tmp_from_ib || t->versioned_by_sql() ||
917
+ thd->variables.vers_innodb_algorithm_simple)
918
+ {
919
+ switch (vers_conditions.type)
917
920
{
918
- switch (vers_conditions.type)
921
+ case FOR_SYSTEM_TIME_UNSPECIFIED:
922
+ if (t->vers_start_field()->real_type() != MYSQL_TYPE_LONGLONG)
919
923
{
920
- case FOR_SYSTEM_TIME_UNSPECIFIED:
921
- if (t->vers_start_field()->real_type() != MYSQL_TYPE_LONGLONG)
922
- {
923
- MYSQL_TIME max_time;
924
- thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE);
925
- max_time.second_part= TIME_MAX_SECOND_PART;
926
- curr= newx Item_datetime_literal(thd, &max_time,
927
- TIME_SECOND_PART_DIGITS);
928
- cond1= newx Item_func_eq(thd, row_end, curr);
929
- }
930
- else
931
- {
932
- curr= newx Item_int(thd, ULONGLONG_MAX);
933
- cond1= newx Item_func_eq(thd, row_end, curr);
934
- }
935
- break;
936
- case FOR_SYSTEM_TIME_AS_OF:
937
- cond1= newx Item_func_le(thd, row_start,
938
- vers_conditions.start);
939
- cond2= newx Item_func_gt(thd, row_end,
940
- vers_conditions.start);
941
- break;
942
- case FOR_SYSTEM_TIME_FROM_TO:
943
- cond1= newx Item_func_lt(thd, row_start,
944
- vers_conditions.end);
945
- cond2= newx Item_func_ge(thd, row_end,
946
- vers_conditions.start);
947
- break;
948
- case FOR_SYSTEM_TIME_BETWEEN:
949
- cond1= newx Item_func_le(thd, row_start,
950
- vers_conditions.end);
951
- cond2= newx Item_func_ge(thd, row_end,
952
- vers_conditions.start);
953
- break;
954
- case FOR_SYSTEM_TIME_BEFORE:
955
- cond1= newx Item_func_lt(thd, row_end,
956
- vers_conditions.start);
957
- break;
958
- default:
959
- DBUG_ASSERT(0);
924
+ MYSQL_TIME max_time;
925
+ thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE);
926
+ max_time.second_part= TIME_MAX_SECOND_PART;
927
+ curr= newx Item_datetime_literal(thd, &max_time,
928
+ TIME_SECOND_PART_DIGITS);
929
+ cond1= newx Item_func_eq(thd, row_end, curr);
960
930
}
961
- }
962
- else
963
- {
964
- DBUG_ASSERT(table->table->s && table->table->s->db_plugin);
965
-
966
- Item *trx_id0, *trx_id1;
967
-
968
- switch (vers_conditions.type)
931
+ else
969
932
{
970
- case FOR_SYSTEM_TIME_UNSPECIFIED:
971
933
curr= newx Item_int(thd, ULONGLONG_MAX);
972
934
cond1= newx Item_func_eq(thd, row_end, curr);
973
- break;
974
- case FOR_SYSTEM_TIME_AS_OF:
975
- trx_id0= vers_conditions.unit_start == UNIT_TIMESTAMP ?
976
- newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID) :
977
- vers_conditions.start;
978
- cond1= newx Item_func_vtq_trx_sees_eq(thd, trx_id0, row_start);
979
- cond2= newx Item_func_vtq_trx_sees(thd, row_end, trx_id0);
980
- break;
981
- case FOR_SYSTEM_TIME_FROM_TO:
982
- case FOR_SYSTEM_TIME_BETWEEN:
983
- trx_id0= vers_conditions.unit_start == UNIT_TIMESTAMP ?
984
- newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID, true) :
985
- vers_conditions.start;
986
- trx_id1= vers_conditions.unit_end == UNIT_TIMESTAMP ?
987
- newx Item_func_vtq_id(thd, vers_conditions.end, TR_table::FLD_TRX_ID, false) :
988
- vers_conditions.end;
989
- cond1= vers_conditions.type == FOR_SYSTEM_TIME_FROM_TO ?
990
- newx Item_func_vtq_trx_sees(thd, trx_id1, row_start) :
991
- newx Item_func_vtq_trx_sees_eq(thd, trx_id1, row_start);
992
- cond2= newx Item_func_vtq_trx_sees_eq(thd, row_end, trx_id0);
993
- break;
994
- case FOR_SYSTEM_TIME_BEFORE:
995
- trx_id0= vers_conditions.unit_start == UNIT_TIMESTAMP ?
996
- newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID) :
997
- vers_conditions.start;
998
- cond1= newx Item_func_lt(thd, row_end, trx_id0);
999
- break;
1000
- default:
1001
- DBUG_ASSERT(0);
1002
935
}
936
+ break;
937
+ case FOR_SYSTEM_TIME_AS_OF:
938
+ cond1= newx Item_func_le(thd, row_start,
939
+ vers_conditions.start);
940
+ cond2= newx Item_func_gt(thd, row_end,
941
+ vers_conditions.start);
942
+ break;
943
+ case FOR_SYSTEM_TIME_FROM_TO:
944
+ cond1= newx Item_func_lt(thd, row_start,
945
+ vers_conditions.end);
946
+ cond2= newx Item_func_ge(thd, row_end,
947
+ vers_conditions.start);
948
+ break;
949
+ case FOR_SYSTEM_TIME_BETWEEN:
950
+ cond1= newx Item_func_le(thd, row_start,
951
+ vers_conditions.end);
952
+ cond2= newx Item_func_ge(thd, row_end,
953
+ vers_conditions.start);
954
+ break;
955
+ case FOR_SYSTEM_TIME_BEFORE:
956
+ cond1= newx Item_func_lt(thd, row_end,
957
+ vers_conditions.start);
958
+ break;
959
+ default:
960
+ DBUG_ASSERT(0);
1003
961
}
962
+ }
963
+ else
964
+ {
965
+ DBUG_ASSERT(table->table->s && table->table->s->db_plugin);
966
+
967
+ Item *trx_id0, *trx_id1;
1004
968
1005
- if (cond1 )
969
+ switch (vers_conditions.type )
1006
970
{
1007
- vers_cond= and_items(thd,
1008
- vers_cond,
1009
- and_items(thd,
1010
- cond2,
1011
- cond1));
1012
- if (table->is_view_or_derived())
1013
- vers_cond= or_items(thd, vers_cond, newx Item_func_isnull(thd, row_end));
971
+ case FOR_SYSTEM_TIME_UNSPECIFIED:
972
+ curr= newx Item_int(thd, ULONGLONG_MAX);
973
+ cond1= newx Item_func_eq(thd, row_end, curr);
974
+ break;
975
+ case FOR_SYSTEM_TIME_AS_OF:
976
+ trx_id0= vers_conditions.unit_start == UNIT_TIMESTAMP ?
977
+ newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID) :
978
+ vers_conditions.start;
979
+ cond1= newx Item_func_vtq_trx_sees_eq(thd, trx_id0, row_start);
980
+ cond2= newx Item_func_vtq_trx_sees(thd, row_end, trx_id0);
981
+ break;
982
+ case FOR_SYSTEM_TIME_FROM_TO:
983
+ case FOR_SYSTEM_TIME_BETWEEN:
984
+ trx_id0= vers_conditions.unit_start == UNIT_TIMESTAMP ?
985
+ newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID, true) :
986
+ vers_conditions.start;
987
+ trx_id1= vers_conditions.unit_end == UNIT_TIMESTAMP ?
988
+ newx Item_func_vtq_id(thd, vers_conditions.end, TR_table::FLD_TRX_ID, false) :
989
+ vers_conditions.end;
990
+ cond1= vers_conditions.type == FOR_SYSTEM_TIME_FROM_TO ?
991
+ newx Item_func_vtq_trx_sees(thd, trx_id1, row_start) :
992
+ newx Item_func_vtq_trx_sees_eq(thd, trx_id1, row_start);
993
+ cond2= newx Item_func_vtq_trx_sees_eq(thd, row_end, trx_id0);
994
+ break;
995
+ case FOR_SYSTEM_TIME_BEFORE:
996
+ trx_id0= vers_conditions.unit_start == UNIT_TIMESTAMP ?
997
+ newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID) :
998
+ vers_conditions.start;
999
+ cond1= newx Item_func_lt(thd, row_end, trx_id0);
1000
+ break;
1001
+ default:
1002
+ DBUG_ASSERT(0);
1014
1003
}
1015
- } // if (... table->table->versioned())
1004
+ }
1005
+
1006
+ if (cond1)
1007
+ {
1008
+ vers_cond= and_items(thd,
1009
+ vers_cond,
1010
+ and_items(thd,
1011
+ cond2,
1012
+ cond1));
1013
+ if (table->is_view_or_derived())
1014
+ vers_cond= or_items(thd, vers_cond, newx Item_func_isnull(thd, row_end));
1015
+ }
1016
1016
} // for (table= tables; ...)
1017
1017
1018
1018
if (vers_cond)
0 commit comments