| 30 | PG_FUNCTION_INFO_V1(test_predtest); |
| 31 | |
| 32 | Datum |
| 33 | test_predtest(PG_FUNCTION_ARGS) |
| 34 | { |
| 35 | text *txt = PG_GETARG_TEXT_PP(0); |
| 36 | char *query_string = text_to_cstring(txt); |
| 37 | SPIPlanPtr spiplan; |
| 38 | int spirc; |
| 39 | TupleDesc tupdesc; |
| 40 | bool s_i_holds, |
| 41 | w_i_holds, |
| 42 | s_r_holds, |
| 43 | w_r_holds; |
| 44 | CachedPlan *cplan; |
| 45 | PlannedStmt *stmt; |
| 46 | Plan *plan; |
| 47 | Expr *clause1; |
| 48 | Expr *clause2; |
| 49 | bool strong_implied_by, |
| 50 | weak_implied_by, |
| 51 | strong_refuted_by, |
| 52 | weak_refuted_by; |
| 53 | Datum values[8]; |
| 54 | bool nulls[8]; |
| 55 | int i; |
| 56 | |
| 57 | /* We use SPI to parse, plan, and execute the test query */ |
| 58 | if (SPI_connect() != SPI_OK_CONNECT) |
| 59 | elog(ERROR, "SPI_connect failed"); |
| 60 | |
| 61 | /* |
| 62 | * First, plan and execute the query, and inspect the results. To the |
| 63 | * extent that the query fully exercises the two expressions, this |
| 64 | * provides an experimental indication of whether implication or |
| 65 | * refutation holds. |
| 66 | */ |
| 67 | spiplan = SPI_prepare(query_string, 0, NULL); |
| 68 | if (spiplan == NULL) |
| 69 | elog(ERROR, "SPI_prepare failed for \"%s\"", query_string); |
| 70 | |
| 71 | spirc = SPI_execute_plan(spiplan, NULL, NULL, true, 0); |
| 72 | if (spirc != SPI_OK_SELECT) |
| 73 | elog(ERROR, "failed to execute \"%s\"", query_string); |
| 74 | tupdesc = SPI_tuptable->tupdesc; |
| 75 | if (tupdesc->natts != 2 || |
| 76 | TupleDescAttr(tupdesc, 0)->atttypid != BOOLOID || |
| 77 | TupleDescAttr(tupdesc, 1)->atttypid != BOOLOID) |
| 78 | elog(ERROR, "query must yield two boolean columns"); |
| 79 | |
| 80 | s_i_holds = w_i_holds = s_r_holds = w_r_holds = true; |
| 81 | for (i = 0; i < SPI_processed; i++) |
| 82 | { |
| 83 | HeapTuple tup = SPI_tuptable->vals[i]; |
| 84 | Datum dat; |
| 85 | bool isnull; |
| 86 | char c1, |
| 87 | c2; |
| 88 | |
| 89 | /* Extract column values in a 3-way representation */ |
nothing calls this directly
no test coverage detected