19 #include <NdbScanFilter.hpp>
22 #include <Interpreter.hpp>
23 #include <signaldata/AttrInfo.hpp>
27 #define INT_DEBUG(x) \
28 { const char* tmp = NdbEnv_GetEnv("INT_DEBUG", (char*)0, 0); \
29 if (tmp != 0 && strlen(tmp) != 0) { ndbout << "INT:"; ndbout_c x; } }
59 const void * value, Uint32 len);
65 m_current.m_popCount = 0;
66 m_current.m_ownLabel = 0;
67 m_current.m_trueLabel = ~0;
68 m_current.m_falseLabel = ~0;
72 m_associated_op= NULL;
84 int propagateErrorFromCode()
92 if (codeError.
code == 4518)
93 m_error.
code = NdbScanFilter::FilterTooLarge;
103 int handleFilterDefined()
107 return propagateErrorFromCode();
113 if (m_associated_op != NULL)
123 const Uint32 LabelExit = ~0;
129 DBUG_ENTER(
"NdbScanFilter::NdbScanFilter(NdbInterpretedCode)");
137 DBUG_ENTER(
"NdbScanFilter::NdbScanFilter(NdbOperation)");
163 NdbScanFilter::~NdbScanFilter()
170 if (m_impl.m_error.
code != 0)
return -1;
172 if (m_impl.m_stack2.push_back(m_impl.m_negative))
175 m_impl.m_error.
code= 4000;
180 INT_DEBUG((
"Begin(AND)"));
181 if(m_impl.m_negative == 1){
186 INT_DEBUG((
"Begin(OR)"));
187 if(m_impl.m_negative == 1){
192 INT_DEBUG((
"Begin(NAND)"));
193 if(m_impl.m_negative == 0){
195 m_impl.m_negative = 1;
198 m_impl.m_negative = 0;
202 INT_DEBUG((
"Begin(NOR)"));
203 if(m_impl.m_negative == 0){
205 m_impl.m_negative = 1;
208 m_impl.m_negative = 0;
213 if(group == m_impl.m_current.m_group){
217 m_impl.m_current.m_popCount++;
226 if (m_impl.m_stack.push_back(m_impl.m_current))
229 m_impl.m_error.
code= 4000;
232 m_impl.m_current.m_group =
group;
233 m_impl.m_current.m_ownLabel = m_impl.m_label++;
234 m_impl.m_current.m_popCount = 0;
239 m_impl.m_current.m_falseLabel = m_impl.m_current.m_ownLabel;
240 m_impl.m_current.m_trueLabel = tmp.m_trueLabel;
244 m_impl.m_current.m_falseLabel = tmp.m_falseLabel;
245 m_impl.m_current.m_trueLabel = m_impl.m_current.m_ownLabel;
249 m_impl.m_error.
code= 4260;
258 if (m_impl.m_error.
code != 0)
return -1;
260 if(m_impl.m_stack2.size() == 0){
262 m_impl.m_error.
code= 4259;
265 m_impl.m_negative = m_impl.m_stack2.back();
266 m_impl.m_stack2.erase(m_impl.m_stack2.size() - 1);
268 switch(m_impl.m_current.m_group){
270 INT_DEBUG((
"End(AND pc=%d)", m_impl.m_current.m_popCount));
273 INT_DEBUG((
"End(OR pc=%d)", m_impl.m_current.m_popCount));
276 INT_DEBUG((
"End(NAND pc=%d)", m_impl.m_current.m_popCount));
279 INT_DEBUG((
"End(NOR pc=%d)", m_impl.m_current.m_popCount));
283 if(m_impl.m_current.m_popCount > 0){
284 m_impl.m_current.m_popCount--;
289 if(m_impl.m_stack.size() == 0){
291 m_impl.m_error.
code= 4259;
294 m_impl.m_current = m_impl.m_stack.back();
295 m_impl.m_stack.erase(m_impl.m_stack.size() - 1);
299 if(tmp.m_trueLabel == (Uint32)~0){
300 if (m_impl.m_code->interpret_exit_ok() == -1)
301 return m_impl.propagateErrorFromCode();
303 if (m_impl.m_code->branch_label(tmp.m_trueLabel) == -1)
304 return m_impl.propagateErrorFromCode();
308 if(tmp.m_trueLabel == (Uint32)~0){
309 if (m_impl.m_code->interpret_exit_nok() == -1)
310 return m_impl.propagateErrorFromCode();
312 if (m_impl.m_code->branch_label(tmp.m_falseLabel) == -1)
313 return m_impl.propagateErrorFromCode();
317 if(tmp.m_falseLabel == (Uint32)~0){
318 if (m_impl.m_code->interpret_exit_nok() == -1)
319 return m_impl.propagateErrorFromCode();
321 if (m_impl.m_code->branch_label(tmp.m_falseLabel) == -1)
322 return m_impl.propagateErrorFromCode();
326 if(tmp.m_falseLabel == (Uint32)~0){
327 if (m_impl.m_code->interpret_exit_ok() == -1)
328 return m_impl.propagateErrorFromCode();
330 if (m_impl.m_code->branch_label(tmp.m_trueLabel) == -1)
331 return m_impl.propagateErrorFromCode();
336 m_impl.m_error.
code= 4260;
340 if (m_impl.m_code->def_label(tmp.m_ownLabel) == -1)
341 return m_impl.propagateErrorFromCode();
343 if(m_impl.m_stack.size() == 0){
347 if (m_impl.m_code->interpret_exit_nok() == -1)
348 return m_impl.propagateErrorFromCode();
352 if (m_impl.m_code->interpret_exit_ok() == -1)
353 return m_impl.propagateErrorFromCode();
357 m_impl.m_error.
code= 4260;
362 return m_impl.handleFilterDefined();
369 if(m_impl.m_error.
code != 0)
return -1;
374 m_impl.m_error.
code= 4260;
378 if(m_impl.m_current.m_trueLabel == (Uint32)~0){
379 if (m_impl.m_code->interpret_exit_ok() == -1)
380 return m_impl.propagateErrorFromCode();
382 if (m_impl.m_code->branch_label(m_impl.m_current.m_trueLabel) == -1)
383 return m_impl.propagateErrorFromCode();
391 if (m_impl.m_error.
code != 0)
return -1;
395 m_impl.m_error.
code= 4260;
399 if(m_impl.m_current.m_falseLabel == (Uint32)~0){
400 if (m_impl.m_code->interpret_exit_nok() == -1)
401 return m_impl.propagateErrorFromCode();
403 if (m_impl.m_code->branch_label(m_impl.m_current.m_falseLabel) == -1)
404 return m_impl.propagateErrorFromCode();
410 #define action(x, y, z)
419 Branch1 m_branches[5];
430 static const tab2 table2[] = {
435 &NdbInterpretedCode::branch_col_ne_null,
436 &NdbInterpretedCode::branch_col_eq_null,
437 &NdbInterpretedCode::branch_col_eq_null,
438 &NdbInterpretedCode::branch_col_ne_null } }
444 &NdbInterpretedCode::branch_col_eq_null,
445 &NdbInterpretedCode::branch_col_ne_null,
446 &NdbInterpretedCode::branch_col_ne_null,
447 &NdbInterpretedCode::branch_col_eq_null } }
450 const int tab2_sz =
sizeof(table2)/
sizeof(table2[0]);
455 if (m_error.
code != 0)
return -1;
457 if(op < 0 || op >= tab2_sz){
470 Branch1 branch = table2[op].m_branches[m_current.m_group];
471 if ((m_code->* branch)(AttrId, m_current.m_ownLabel) == -1)
472 return propagateErrorFromCode();
479 if (m_impl.m_error.
code != 0)
return -1;
481 if(m_impl.m_negative == 1)
482 return m_impl.cond_col(Interpreter::IS_NOT_NULL, AttrId);
484 return m_impl.cond_col(Interpreter::IS_NULL, AttrId);
489 if (m_impl.m_error.
code != 0)
return -1;
491 if(m_impl.m_negative == 1)
492 return m_impl.cond_col(Interpreter::IS_NULL, AttrId);
494 return m_impl.cond_col(Interpreter::IS_NOT_NULL, AttrId);
501 StrBranch2 m_branches[5];
513 static const tab3 table3[] = {
518 &NdbInterpretedCode::branch_col_ne,
519 &NdbInterpretedCode::branch_col_eq,
520 &NdbInterpretedCode::branch_col_ne,
521 &NdbInterpretedCode::branch_col_eq } }
527 &NdbInterpretedCode::branch_col_eq,
528 &NdbInterpretedCode::branch_col_ne,
529 &NdbInterpretedCode::branch_col_eq,
530 &NdbInterpretedCode::branch_col_ne } }
536 &NdbInterpretedCode::branch_col_le,
537 &NdbInterpretedCode::branch_col_gt,
538 &NdbInterpretedCode::branch_col_le,
539 &NdbInterpretedCode::branch_col_gt } }
545 &NdbInterpretedCode::branch_col_lt,
546 &NdbInterpretedCode::branch_col_ge,
547 &NdbInterpretedCode::branch_col_lt,
548 &NdbInterpretedCode::branch_col_ge } }
554 &NdbInterpretedCode::branch_col_ge,
555 &NdbInterpretedCode::branch_col_lt,
556 &NdbInterpretedCode::branch_col_ge,
557 &NdbInterpretedCode::branch_col_lt } }
563 &NdbInterpretedCode::branch_col_gt,
564 &NdbInterpretedCode::branch_col_le,
565 &NdbInterpretedCode::branch_col_gt,
566 &NdbInterpretedCode::branch_col_le } }
572 &NdbInterpretedCode::branch_col_notlike,
573 &NdbInterpretedCode::branch_col_like,
574 &NdbInterpretedCode::branch_col_notlike,
575 &NdbInterpretedCode::branch_col_like } }
581 &NdbInterpretedCode::branch_col_like,
582 &NdbInterpretedCode::branch_col_notlike,
583 &NdbInterpretedCode::branch_col_like,
584 &NdbInterpretedCode::branch_col_notlike } }
590 &NdbInterpretedCode::branch_col_and_mask_ne_mask,
591 &NdbInterpretedCode::branch_col_and_mask_eq_mask,
592 &NdbInterpretedCode::branch_col_and_mask_ne_mask,
593 &NdbInterpretedCode::branch_col_and_mask_eq_mask } }
599 &NdbInterpretedCode::branch_col_and_mask_eq_mask,
600 &NdbInterpretedCode::branch_col_and_mask_ne_mask,
601 &NdbInterpretedCode::branch_col_and_mask_eq_mask,
602 &NdbInterpretedCode::branch_col_and_mask_ne_mask } }
608 &NdbInterpretedCode::branch_col_and_mask_ne_zero,
609 &NdbInterpretedCode::branch_col_and_mask_eq_zero,
610 &NdbInterpretedCode::branch_col_and_mask_ne_zero,
611 &NdbInterpretedCode::branch_col_and_mask_eq_zero } }
617 &NdbInterpretedCode::branch_col_and_mask_eq_zero,
618 &NdbInterpretedCode::branch_col_and_mask_ne_zero,
619 &NdbInterpretedCode::branch_col_and_mask_eq_zero,
620 &NdbInterpretedCode::branch_col_and_mask_ne_zero } }
623 const int tab3_sz =
sizeof(table3)/
sizeof(table3[0]);
628 const void * value, Uint32 len){
629 if (m_error.
code != 0)
return -1;
631 if(op < 0 || op >= tab3_sz){
662 branch = table3[op].m_branches[(Uint32)(m_current.m_group)];
683 if ((m_code->* branch)(value, len, AttrId, m_current.m_ownLabel) == -1)
684 return propagateErrorFromCode();
691 const void *val, Uint32 len)
709 return m_impl.
cond_col_const(Interpreter::NOT_LIKE, ColId, val, len);
711 return m_impl.
cond_col_const(Interpreter::AND_EQ_MASK, ColId, val, len);
713 return m_impl.
cond_col_const(Interpreter::AND_NE_MASK, ColId, val, len);
715 return m_impl.
cond_col_const(Interpreter::AND_EQ_ZERO, ColId, val, len);
717 return m_impl.
cond_col_const(Interpreter::AND_NE_ZERO, ColId, val, len);
726 ndberror_update(&ndberror);
733 update(m_impl.m_error);
734 return m_impl.m_error;
744 if (m_impl.m_associated_op != NULL)
747 return m_impl.m_code;
756 return m_impl.m_associated_op;
764 ndbout <<
"a > 7 AND b < 9 AND c = 4" << endl;
776 ndbout <<
"a > 7 OR b < 9 OR c = 4" << endl;
788 ndbout <<
"a > 7 AND (b < 9 OR c = 4)" << endl;
802 ndbout <<
"a > 7 AND (b < 9 AND c = 4)" << endl;
816 ndbout <<
"(a > 7 AND b < 9) AND c = 4" << endl;
830 ndbout <<
"(a > 7 OR b < 9) AND (c = 4 OR c = 5)" << endl;
847 ndbout <<
"(a > 7 AND b < 9) OR (c = 4 AND c = 5)" << endl;
865 "((a > 7 AND b < 9) OR (c = 4 AND d = 5)) AND "
866 "((e > 6 AND f < 8) OR (g = 2 AND h = 3)) " << endl;