| 1025 | } |
| 1026 | |
| 1027 | static |
| 1028 | Item* period_get_condition(THD *thd, TABLE_LIST *table, SELECT_LEX *select, |
| 1029 | vers_select_conds_t *conds, bool timestamp) |
| 1030 | { |
| 1031 | DBUG_ASSERT(table); |
| 1032 | DBUG_ASSERT(table->table); |
| 1033 | #define newx new (thd->mem_root) |
| 1034 | TABLE_SHARE *share= table->table->s; |
| 1035 | const TABLE_SHARE::period_info_t *period= conds->period; |
| 1036 | |
| 1037 | const LEX_CSTRING &fstart= period->start_field(share)->field_name; |
| 1038 | const LEX_CSTRING &fend= period->end_field(share)->field_name; |
| 1039 | |
| 1040 | conds->field_start= newx Item_field(thd, &select->context, |
| 1041 | table->db, table->alias, |
| 1042 | thd->strmake_lex_cstring(fstart)); |
| 1043 | conds->field_end= newx Item_field(thd, &select->context, |
| 1044 | table->db, table->alias, |
| 1045 | thd->strmake_lex_cstring(fend)); |
| 1046 | |
| 1047 | Item *cond1= NULL, *cond2= NULL, *cond3= NULL, *curr= NULL; |
| 1048 | if (timestamp) |
| 1049 | { |
| 1050 | MYSQL_TIME max_time; |
| 1051 | switch (conds->type) |
| 1052 | { |
| 1053 | case SYSTEM_TIME_UNSPECIFIED: |
| 1054 | case SYSTEM_TIME_HISTORY: |
| 1055 | { |
| 1056 | thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE); |
| 1057 | max_time.second_part= TIME_MAX_SECOND_PART; |
| 1058 | Datetime dt(&max_time); |
| 1059 | curr= newx Item_datetime_literal(thd, &dt, TIME_SECOND_PART_DIGITS); |
| 1060 | if (conds->type == SYSTEM_TIME_UNSPECIFIED) |
| 1061 | cond1= newx Item_func_eq(thd, conds->field_end, curr); |
| 1062 | else |
| 1063 | cond1= newx Item_func_lt(thd, conds->field_end, curr); |
| 1064 | break; |
| 1065 | } |
| 1066 | case SYSTEM_TIME_AS_OF: |
| 1067 | cond1= newx Item_func_le(thd, conds->field_start, conds->start.item); |
| 1068 | cond2= newx Item_func_gt(thd, conds->field_end, conds->start.item); |
| 1069 | break; |
| 1070 | case SYSTEM_TIME_FROM_TO: |
| 1071 | cond1= newx Item_func_lt(thd, conds->field_start, conds->end.item); |
| 1072 | cond2= newx Item_func_gt(thd, conds->field_end, conds->start.item); |
| 1073 | cond3= newx Item_func_lt(thd, conds->start.item, conds->end.item); |
| 1074 | break; |
| 1075 | case SYSTEM_TIME_BETWEEN: |
| 1076 | cond1= newx Item_func_le(thd, conds->field_start, conds->end.item); |
| 1077 | cond2= newx Item_func_gt(thd, conds->field_end, conds->start.item); |
| 1078 | cond3= newx Item_func_le(thd, conds->start.item, conds->end.item); |
| 1079 | break; |
| 1080 | case SYSTEM_TIME_BEFORE: |
| 1081 | cond1= newx Item_func_history(thd, conds->field_end); |
| 1082 | cond2= newx Item_func_lt(thd, conds->field_end, conds->start.item); |
| 1083 | break; |
| 1084 | default: |
no test coverage detected