* ExecHashJoinSaveTuple * save a tuple to a batch file. * * The data recorded in the file for each tuple is its hash value, * then the tuple in MinimalTuple format. * * Note: it is important always to call this in the regular executor * context, not in a shorter-lived context; else the temp file buffers * will get messed up. */
| 1563 | * will get messed up. |
| 1564 | */ |
| 1565 | void |
| 1566 | ExecHashJoinSaveTuple(PlanState *ps, MinimalTuple tuple, uint32 hashvalue, |
| 1567 | HashJoinTable hashtable, BufFile **fileptr, |
| 1568 | MemoryContext bfCxt) |
| 1569 | { |
| 1570 | BufFile *file = *fileptr; |
| 1571 | |
| 1572 | if (hashtable->work_set == NULL) |
| 1573 | { |
| 1574 | /* |
| 1575 | * First time spilling. |
| 1576 | */ |
| 1577 | if (hashtable->hjstate->js.ps.instrument) |
| 1578 | { |
| 1579 | hashtable->hjstate->js.ps.instrument->workfileCreated = true; |
| 1580 | } |
| 1581 | |
| 1582 | MemoryContext oldcxt; |
| 1583 | |
| 1584 | oldcxt = MemoryContextSwitchTo(bfCxt); |
| 1585 | hashtable->work_set = workfile_mgr_create_set("HashJoin", NULL, true /* hold pin */); |
| 1586 | MemoryContextSwitchTo(oldcxt); |
| 1587 | } |
| 1588 | |
| 1589 | if (file == NULL) |
| 1590 | { |
| 1591 | MemoryContext oldcxt; |
| 1592 | |
| 1593 | oldcxt = MemoryContextSwitchTo(bfCxt); |
| 1594 | |
| 1595 | /* First write to this batch file, so create it */ |
| 1596 | Assert(hashtable->work_set != NULL); |
| 1597 | file = BufFileCreateTempInSet("HashJoin", false /* interXact */, |
| 1598 | hashtable->work_set); |
| 1599 | BufFilePledgeSequential(file); /* allow compression */ |
| 1600 | *fileptr = file; |
| 1601 | |
| 1602 | elog(gp_workfile_caching_loglevel, "create batch file %s", |
| 1603 | BufFileGetFilename(file)); |
| 1604 | |
| 1605 | MemoryContextSwitchTo(oldcxt); |
| 1606 | } |
| 1607 | |
| 1608 | BufFileWrite(file, (void *) &hashvalue, sizeof(uint32)); |
| 1609 | BufFileWrite(file, (void *) tuple, tuple->t_len); |
| 1610 | } |
| 1611 | |
| 1612 | /* |
| 1613 | * ExecHashJoinGetSavedTuple |
no test coverage detected