@@ -677,53 +677,37 @@ bool vers_select_conds_t::init_from_sysvar(THD *thd)
677677{
678678 vers_asof_timestamp_t &in= thd->variables.vers_asof_timestamp;
679679 type= (vers_system_time_t) in.type;
680- unit_start = VERS_TIMESTAMP;
680+ start.unit = VERS_TIMESTAMP;
681681 from_query= false;
682682 if (type != SYSTEM_TIME_UNSPECIFIED && type != SYSTEM_TIME_ALL)
683683 {
684684 DBUG_ASSERT(type == SYSTEM_TIME_AS_OF);
685- start= new (thd->mem_root)
685+ start.item = new (thd->mem_root)
686686 Item_datetime_literal(thd, &in.ltime, TIME_SECOND_PART_DIGITS);
687- if (!start)
687+ if (!start.item )
688688 return true;
689689 }
690690 else
691- start= NULL;
692- end= NULL ;
691+ start.item = NULL;
692+ end.empty() ;
693693 return false;
694694}
695695
696696void vers_select_conds_t::print(String *str, enum_query_type query_type)
697697{
698- const static LEX_CSTRING unit_type[]=
699- {
700- { STRING_WITH_LEN("") },
701- { STRING_WITH_LEN("TIMESTAMP ") },
702- { STRING_WITH_LEN("TRANSACTION ") }
703- };
704698 switch (type) {
705699 case SYSTEM_TIME_UNSPECIFIED:
706700 break;
707701 case SYSTEM_TIME_AS_OF:
708- str->append(STRING_WITH_LEN(" FOR SYSTEM_TIME AS OF "));
709- str->append(unit_type + unit_start);
710- start->print(str, query_type);
702+ start.print(str, query_type, STRING_WITH_LEN(" FOR SYSTEM_TIME AS OF "));
711703 break;
712704 case SYSTEM_TIME_FROM_TO:
713- str->append(STRING_WITH_LEN(" FOR SYSTEM_TIME FROM "));
714- str->append(unit_type + unit_start);
715- start->print(str, query_type);
716- str->append(STRING_WITH_LEN(" TO "));
717- str->append(unit_type + unit_end);
718- end->print(str, query_type);
705+ start.print(str, query_type, STRING_WITH_LEN(" FOR SYSTEM_TIME FROM "));
706+ end.print(str, query_type, STRING_WITH_LEN(" TO "));
719707 break;
720708 case SYSTEM_TIME_BETWEEN:
721- str->append(STRING_WITH_LEN(" FOR SYSTEM_TIME BETWEEN "));
722- str->append(unit_type + unit_start);
723- start->print(str, query_type);
724- str->append(STRING_WITH_LEN(" AND "));
725- str->append(unit_type + unit_end);
726- end->print(str, query_type);
709+ start.print(str, query_type, STRING_WITH_LEN(" FOR SYSTEM_TIME BETWEEN "));
710+ end.print(str, query_type, STRING_WITH_LEN(" AND "));
727711 break;
728712 case SYSTEM_TIME_BEFORE:
729713 DBUG_ASSERT(0);
@@ -871,8 +855,8 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
871855 vers_system_time_t/VERS_TRX_ID at stage of fix_fields()
872856 (this is large refactoring). */
873857 vers_conditions.resolve_units(timestamps_only);
874- if (timestamps_only && (vers_conditions.unit_start == VERS_TRX_ID ||
875- vers_conditions.unit_end == VERS_TRX_ID))
858+ if (timestamps_only && (vers_conditions.start.unit == VERS_TRX_ID ||
859+ vers_conditions.end.unit == VERS_TRX_ID))
876860 {
877861 my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name.str);
878862 DBUG_RETURN(-1);
@@ -889,53 +873,8 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
889873 {
890874 if (vers_conditions)
891875 {
892- if (vers_conditions.start)
893- {
894- if (!vers_conditions.unit_start)
895- vers_conditions.unit_start= t->s->versioned;
896- switch (vers_conditions.unit_start)
897- {
898- case VERS_TIMESTAMP:
899- {
900- vers_conditions.start= newx Item_datetime_from_unixtime_typecast(
901- thd, vers_conditions.start, 6);
902- break;
903- }
904- case VERS_TRX_ID:
905- {
906- vers_conditions.start= newx Item_longlong_typecast(
907- thd, vers_conditions.start);
908- break;
909- }
910- default:
911- DBUG_ASSERT(0);
912- break;
913- }
914- }
915-
916- if (vers_conditions.end)
917- {
918- if (!vers_conditions.unit_end)
919- vers_conditions.unit_end= t->s->versioned;
920- switch (vers_conditions.unit_end)
921- {
922- case VERS_TIMESTAMP:
923- {
924- vers_conditions.end= newx Item_datetime_from_unixtime_typecast(
925- thd, vers_conditions.end, 6);
926- break;
927- }
928- case VERS_TRX_ID:
929- {
930- vers_conditions.end= newx Item_longlong_typecast(
931- thd, vers_conditions.end);
932- break;
933- }
934- default:
935- DBUG_ASSERT(0);
936- break;
937- }
938- }
876+ vers_conditions.start.add_typecast(thd, t->s->versioned);
877+ vers_conditions.end.add_typecast(thd, t->s->versioned);
939878 }
940879 switch (vers_conditions.type)
941880 {
@@ -957,26 +896,19 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
957896 cond1= or_items(thd, cond1, newx Item_func_isnull(thd, row_end));
958897 break;
959898 case SYSTEM_TIME_AS_OF:
960- cond1= newx Item_func_le(thd, row_start,
961- vers_conditions.start);
962- cond2= newx Item_func_gt(thd, row_end,
963- vers_conditions.start);
899+ cond1= newx Item_func_le(thd, row_start, vers_conditions.start.item);
900+ cond2= newx Item_func_gt(thd, row_end, vers_conditions.start.item);
964901 break;
965902 case SYSTEM_TIME_FROM_TO:
966- cond1= newx Item_func_lt(thd, row_start,
967- vers_conditions.end);
968- cond2= newx Item_func_ge(thd, row_end,
969- vers_conditions.start);
903+ cond1= newx Item_func_lt(thd, row_start, vers_conditions.end.item);
904+ cond2= newx Item_func_ge(thd, row_end, vers_conditions.start.item);
970905 break;
971906 case SYSTEM_TIME_BETWEEN:
972- cond1= newx Item_func_le(thd, row_start,
973- vers_conditions.end);
974- cond2= newx Item_func_ge(thd, row_end,
975- vers_conditions.start);
907+ cond1= newx Item_func_le(thd, row_start, vers_conditions.end.item);
908+ cond2= newx Item_func_ge(thd, row_end, vers_conditions.start.item);
976909 break;
977910 case SYSTEM_TIME_BEFORE:
978- cond1= newx Item_func_lt(thd, row_end,
979- vers_conditions.start);
911+ cond1= newx Item_func_lt(thd, row_end, vers_conditions.start.item);
980912 break;
981913 default:
982914 DBUG_ASSERT(0);
@@ -995,29 +927,29 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
995927 cond1= newx Item_func_eq(thd, row_end, curr);
996928 break;
997929 case SYSTEM_TIME_AS_OF:
998- trx_id0= vers_conditions.unit_start == VERS_TIMESTAMP ?
999- newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID) :
1000- vers_conditions.start;
930+ trx_id0= vers_conditions.start.unit == VERS_TIMESTAMP
931+ ? newx Item_func_vtq_id(thd, vers_conditions.start.item , TR_table::FLD_TRX_ID)
932+ : vers_conditions.start.item ;
1001933 cond1= newx Item_func_vtq_trx_sees_eq(thd, trx_id0, row_start);
1002934 cond2= newx Item_func_vtq_trx_sees(thd, row_end, trx_id0);
1003935 break;
1004936 case SYSTEM_TIME_FROM_TO:
1005937 case SYSTEM_TIME_BETWEEN:
1006- trx_id0= vers_conditions.unit_start == VERS_TIMESTAMP ?
1007- newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID, true) :
1008- vers_conditions.start;
1009- trx_id1= vers_conditions.unit_end == VERS_TIMESTAMP ?
1010- newx Item_func_vtq_id(thd, vers_conditions.end, TR_table::FLD_TRX_ID, false) :
1011- vers_conditions.end;
1012- cond1= vers_conditions.type == SYSTEM_TIME_FROM_TO ?
1013- newx Item_func_vtq_trx_sees(thd, trx_id1, row_start) :
1014- newx Item_func_vtq_trx_sees_eq(thd, trx_id1, row_start);
938+ trx_id0= vers_conditions.start.unit == VERS_TIMESTAMP
939+ ? newx Item_func_vtq_id(thd, vers_conditions.start.item , TR_table::FLD_TRX_ID, true)
940+ : vers_conditions.start.item ;
941+ trx_id1= vers_conditions.end.unit == VERS_TIMESTAMP
942+ ? newx Item_func_vtq_id(thd, vers_conditions.end.item , TR_table::FLD_TRX_ID, false)
943+ : vers_conditions.end.item ;
944+ cond1= vers_conditions.type == SYSTEM_TIME_FROM_TO
945+ ? newx Item_func_vtq_trx_sees(thd, trx_id1, row_start)
946+ : newx Item_func_vtq_trx_sees_eq(thd, trx_id1, row_start);
1015947 cond2= newx Item_func_vtq_trx_sees_eq(thd, row_end, trx_id0);
1016948 break;
1017949 case SYSTEM_TIME_BEFORE:
1018- trx_id0= vers_conditions.unit_start == VERS_TIMESTAMP ?
1019- newx Item_func_vtq_id(thd, vers_conditions.start, TR_table::FLD_TRX_ID) :
1020- vers_conditions.start;
950+ trx_id0= vers_conditions.start.unit == VERS_TIMESTAMP
951+ ? newx Item_func_vtq_id(thd, vers_conditions.start.item , TR_table::FLD_TRX_ID)
952+ : vers_conditions.start.item ;
1021953 cond1= newx Item_func_lt(thd, row_end, trx_id0);
1022954 break;
1023955 default:
0 commit comments