| 364 | |
| 365 | template <typename T, typename SetType> |
| 366 | void InPredicate::SetLookupPrepare( |
| 367 | FunctionContext* ctx, FunctionContext::FunctionStateScope scope) { |
| 368 | if (scope != FunctionContext::FRAGMENT_LOCAL) return; |
| 369 | |
| 370 | SetLookupState<SetType>* state = new SetLookupState<SetType>; |
| 371 | state->type = ctx->GetArgType(0); |
| 372 | state->contains_null = false; |
| 373 | // Collect all values in a vector to use the bulk insert API to avoid N^2 behavior |
| 374 | // with flat_set. |
| 375 | std::vector<SetType> element_list; |
| 376 | element_list.reserve(ctx->GetNumArgs() - 1); |
| 377 | for (int i = 1; i < ctx->GetNumArgs(); ++i) { |
| 378 | DCHECK(ctx->IsArgConstant(i)); |
| 379 | T* arg = reinterpret_cast<T*>(ctx->GetConstantArg(i)); |
| 380 | if (arg->is_null) { |
| 381 | state->contains_null = true; |
| 382 | } else { |
| 383 | element_list.push_back(GetVal<T, SetType>(state->type, *arg)); |
| 384 | } |
| 385 | } |
| 386 | state->val_set.insert(element_list.begin(), element_list.end()); |
| 387 | ctx->SetFunctionState(scope, state); |
| 388 | } |
| 389 | |
| 390 | template <typename SetType> |
| 391 | void InPredicate::SetLookupClose( |
nothing calls this directly
no test coverage detected