Make SQLSetPos(SQL_DELETE/SQL_REFRESH) more effective.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Tue, 27 Mar 2018 02:08:42 +0000 (11:08 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Tue, 27 Mar 2018 02:08:42 +0000 (11:08 +0900)
Because queries calling currtid(2) like
select .. from .. where ctid=currtid2(.., ..)
cause Seq Scan, their execution may be very slow.
It is better to execute queries using subqueries like
select .. from .. where ctid=(select currtid2(.., ..))
because they cause Tid Scan.
Report and changes by Tsunakawa Takayuki.

results.c

index a4c6caee34ed1e1b3ba1fc9f4b3db268977baf52..7ff96601dcb0f0bb967545d75fe4fc509cbdbd94 100644 (file)
--- a/results.c
+++ b/results.c
@@ -3040,7 +3040,7 @@ MYLOG(DETAIL_LOG_LEVEL, "entering bestitem=%s bestqual=%s\n", SAFE_NAME(ti->best
            if (latest)
            {
                printfPQExpBuffer(&selstr,
-                    "%.*sfrom %s where ctid = currtid2('%s', '%s')",
+                    "%.*sfrom %s where ctid = (select currtid2('%s', '%s'))",
                     (int) from_pos, load_stmt,
                     quoted_table,
                     quoted_table,
@@ -3050,7 +3050,7 @@ MYLOG(DETAIL_LOG_LEVEL, "entering bestitem=%s bestqual=%s\n", SAFE_NAME(ti->best
                printfPQExpBuffer(&selstr, "%.*sfrom %s where ctid = '%s'", (int) from_pos, load_stmt, quoted_table, tidval);
        }
        else if ((flag & USE_INSERTED_TID) != 0)
-           printfPQExpBuffer(&selstr, "%.*sfrom %s where ctid = currtid(0, '(0,0)')", (int) from_pos, load_stmt, quoted_table);
+           printfPQExpBuffer(&selstr, "%.*sfrom %s where ctid = (select currtid(0, '(0,0)'))", (int) from_pos, load_stmt, quoted_table);
        /*
        else if (bestitem && oidint)
        {
@@ -3074,7 +3074,7 @@ MYLOG(DETAIL_LOG_LEVEL, "entering bestitem=%s bestqual=%s\n", SAFE_NAME(ti->best
                char table_fqn[256];
 
                printfPQExpBuffer(&selstr,
-                    "%s where ctid = currtid2('%s', '%s')",
+                    "%s where ctid = (select currtid2('%s', '%s'))",
                     load_stmt,
                     ti_quote(stmt, 0, table_fqn, sizeof(table_fqn)),
                     tidval);
@@ -3083,7 +3083,7 @@ MYLOG(DETAIL_LOG_LEVEL, "entering bestitem=%s bestqual=%s\n", SAFE_NAME(ti->best
                printfPQExpBuffer(&selstr, "%s where ctid = '%s'", load_stmt, tidval);
        }
        else if ((flag & USE_INSERTED_TID) != 0)
-           printfPQExpBuffer(&selstr, "%s where ctid = currtid(0, '(0,0)')", load_stmt);
+           printfPQExpBuffer(&selstr, "%s where ctid = (select currtid(0, '(0,0)'))", load_stmt);
        else if (bestqual)
        {
            andExist = FALSE;