From 585e90b69dcc4e4387d60e93ef046830d1560631 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Fri, 14 Jun 2019 15:05:02 +0800 Subject: [PATCH] Refactor to remove raw_buf_done from external scan scan->raw_buf_done was used for custom external table only, refactor to remove the MERGE_FIXME. cstate->raw_buf_len is safe to use since we operate pstate->raw_buf directly in this case. --- src/backend/access/external/fileam.c | 20 ++++++-------------- src/include/access/relscan.h | 2 -- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/backend/access/external/fileam.c b/src/backend/access/external/fileam.c index a9cf5502e4..f1fbce4dcf 100644 --- a/src/backend/access/external/fileam.c +++ b/src/backend/access/external/fileam.c @@ -159,12 +159,6 @@ external_beginscan(Relation relation, uint32 scancounter, scan->fs_scancounter = scancounter; scan->fs_noop = false; scan->fs_file = NULL; - /* - * GPDB_91_MERGE_FIXME: scan->raw_buf_done is used for custom external - * table only now. Maybe we could refactor externalgettup_custom() to - * remove it. - */ - scan->raw_buf_done = true; /* true so we will read data in first run */ scan->fs_formatter = NULL; scan->fs_constraintExprs = NULL; if (relation->rd_att->constr != NULL && relation->rd_att->constr->num_check > 0) @@ -346,7 +340,6 @@ external_rescan(FileScanDesc scan) scan->fs_pstate->fe_eof = false; scan->fs_pstate->cur_lineno = 0; scan->fs_pstate->cur_attname = NULL; - scan->raw_buf_done = true; /* true so we will read data in first run */ scan->fs_pstate->raw_buf_len = 0; } @@ -911,17 +904,18 @@ externalgettup_custom(FileScanDesc scan) Assert(formatter); /* while didn't finish processing the entire file */ - while (!(scan->raw_buf_done && pstate->fe_eof)) + /* raw_buf_len was set to 0 in BeginCopyFrom() or external_rescan() */ + while (pstate->raw_buf_len != 0 || !pstate->fe_eof) { /* need to fill our buffer with data? */ - if (scan->raw_buf_done) + if (pstate->raw_buf_len == 0) { int bytesread = external_getdata(scan->fs_file, pstate, pstate->raw_buf, RAW_BUF_SIZE); if (bytesread > 0) { appendBinaryStringInfo(&formatter->fmt_databuf, pstate->raw_buf, bytesread); - scan->raw_buf_done = false; + pstate->raw_buf_len = bytesread; } /* HEADER not yet supported ... */ @@ -930,7 +924,7 @@ externalgettup_custom(FileScanDesc scan) } /* while there is still data in our buffer */ - while (!scan->raw_buf_done) + while (pstate->raw_buf_len != 0) { bool error_caught = false; @@ -1019,7 +1013,7 @@ externalgettup_custom(FileScanDesc scan) * Callee consumed all data in the buffer. Prepare * to read more data into it. */ - scan->raw_buf_done = true; + pstate->raw_buf_len = 0; justifyDatabuf(&formatter->fmt_databuf); continue; @@ -1046,8 +1040,6 @@ externalgettup_custom(FileScanDesc scan) errmsg("unexpected end of file"))); } - - /* * if we got here we finished reading all the data. */ diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h index 082726c8f3..0732bf7f67 100644 --- a/src/include/access/relscan.h +++ b/src/include/access/relscan.h @@ -109,8 +109,6 @@ typedef struct FileScanDescData /* current file parse state */ struct CopyStateData *fs_pstate; - bool raw_buf_done; - Form_pg_attribute *attr; AttrNumber num_phys_attrs; Datum *values; -- GitLab