| 1197 | } |
| 1198 | |
| 1199 | int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) |
| 1200 | { |
| 1201 | DBUG_ENTER("SELECT_LEX::vers_setup_conds"); |
| 1202 | const bool update_conds= !skip_setup_conds(thd); |
| 1203 | |
| 1204 | if (!versioned_tables) |
| 1205 | { |
| 1206 | for (TABLE_LIST *table= tables; table; table= table->next_local) |
| 1207 | { |
| 1208 | if (table->table && table->table->versioned()) |
| 1209 | versioned_tables++; |
| 1210 | else if (table->vers_conditions.is_set() && |
| 1211 | (table->is_non_derived() || !table->vers_conditions.used)) |
| 1212 | { |
| 1213 | my_error(ER_VERS_NOT_VERSIONED, MYF(0), table->alias.str); |
| 1214 | DBUG_RETURN(-1); |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | if (versioned_tables == 0) |
| 1220 | DBUG_RETURN(0); |
| 1221 | |
| 1222 | /* For prepared statements we create items on statement arena, |
| 1223 | because they must outlive execution phase for multiple executions. */ |
| 1224 | Query_arena_stmt on_stmt_arena(thd); |
| 1225 | |
| 1226 | // find outer system_time |
| 1227 | SELECT_LEX *outer_slex= outer_select(); |
| 1228 | TABLE_LIST* outer_table= NULL; |
| 1229 | |
| 1230 | if (outer_slex) |
| 1231 | { |
| 1232 | TABLE_LIST* derived= master_unit()->derived; |
| 1233 | // inner SELECT may not be a derived table (derived == NULL) |
| 1234 | while (derived && outer_slex && !derived->vers_conditions.is_set()) |
| 1235 | { |
| 1236 | derived= outer_slex->master_unit()->derived; |
| 1237 | outer_slex= outer_slex->outer_select(); |
| 1238 | } |
| 1239 | if (derived && outer_slex) |
| 1240 | { |
| 1241 | DBUG_ASSERT(derived->vers_conditions.is_set()); |
| 1242 | outer_table= derived; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | bool is_select= false; |
| 1247 | bool use_sysvar= false; |
| 1248 | switch (thd->lex->sql_command) |
| 1249 | { |
| 1250 | case SQLCOM_SELECT: |
| 1251 | use_sysvar= true; |
| 1252 | /* fall through */ |
| 1253 | case SQLCOM_CREATE_TABLE: |
| 1254 | case SQLCOM_INSERT_SELECT: |
| 1255 | case SQLCOM_REPLACE_SELECT: |
| 1256 | case SQLCOM_DELETE_MULTI: |
no test coverage detected