* inserttuple() -- insert a new tuple into the bitmap index. * * This function finds the corresponding bitmap vector associated with * the given attribute value, and inserts a set bit into this bitmap * vector. Each distinct attribute value is stored as a LOV item, which * is stored in a list of LOV pages. * * If there is no LOV item associated with the given attribute value, * a new LOV i
| 2432 | * and the key contains all attributes to be indexed. |
| 2433 | */ |
| 2434 | static void |
| 2435 | inserttuple(Relation rel, Buffer metabuf, uint64 tidnum, |
| 2436 | ItemPointerData ht_ctid pg_attribute_unused(), TupleDesc tupDesc, Datum *attdata, |
| 2437 | bool *nulls, Relation lovHeap, Relation lovIndex, ScanKey scanKey, |
| 2438 | IndexScanDesc scanDesc, bool use_wal) |
| 2439 | { |
| 2440 | BlockNumber lovBlock; |
| 2441 | OffsetNumber lovOffset; |
| 2442 | bool blockNull, offsetNull; |
| 2443 | bool allNulls = true; |
| 2444 | int attno; |
| 2445 | |
| 2446 | BMTIDBuffer buf; |
| 2447 | MemSet(&buf, 0, sizeof(buf)); |
| 2448 | |
| 2449 | /* Check if the values of given attributes are all NULL. */ |
| 2450 | for (attno = 0; attno < tupDesc->natts; attno++) |
| 2451 | { |
| 2452 | if (!nulls[attno]) |
| 2453 | { |
| 2454 | allNulls = false; |
| 2455 | break; |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | /* |
| 2460 | * if the inserting tuple has the value NULL, then the LOV item is |
| 2461 | * the first item in the lovBuffer. |
| 2462 | */ |
| 2463 | if (allNulls) |
| 2464 | { |
| 2465 | lovBlock = BM_LOV_STARTPAGE; |
| 2466 | lovOffset = 1; |
| 2467 | } |
| 2468 | else |
| 2469 | { |
| 2470 | bool res = false; |
| 2471 | |
| 2472 | /* |
| 2473 | * Search through the lov heap and index to find the LOV item which |
| 2474 | * has the same value as the inserting tuple. If such an item is |
| 2475 | * not found, then we create a new LOV item, and insert it into the |
| 2476 | * lov heap and index. |
| 2477 | */ |
| 2478 | |
| 2479 | /* |
| 2480 | * XXX: We lock the meta page to guarantee that only one writer |
| 2481 | * will create a new lovItem at once. However, this does not |
| 2482 | * guard against a race condition where a concurrent writer is |
| 2483 | * inserting the same key as us. So we do another search with |
| 2484 | * SnapshotDirty. If such a key is found, we have to wait for |
| 2485 | * the other guy, and try again. However, this may cause |
| 2486 | * distributed deadlock (see MPP-3155). The fix is to use |
| 2487 | * FrozenTransactionId for tuples in the LOV heap so that |
| 2488 | * all tuples are always visible to any transactions. |
| 2489 | * |
| 2490 | * The problem is, locking the metapage is pretty heavy handed |
| 2491 | * because the read routines need a read lock on it. There are a |
no test coverage detected