Module Name:    src
Committed By:   yamt
Date:           Wed Oct 12 16:24:39 UTC 2011

Modified Files:
        src/share/examples/puffs/pgfs: fix.sql pgfs_subs.c

Log Message:
tweak some sql statements to improve chances to use the index.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/puffs/pgfs/fix.sql \
    src/share/examples/puffs/pgfs/pgfs_subs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/fix.sql
diff -u src/share/examples/puffs/pgfs/fix.sql:1.1 src/share/examples/puffs/pgfs/fix.sql:1.2
--- src/share/examples/puffs/pgfs/fix.sql:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/fix.sql	Wed Oct 12 16:24:39 2011
@@ -1,4 +1,4 @@
--- $NetBSD: fix.sql,v 1.1 2011/10/12 01:05:00 yamt Exp $
+-- $NetBSD: fix.sql,v 1.2 2011/10/12 16:24:39 yamt Exp $
 
 -- Copyright (c)2011 YAMAMOTO Takashi,
 -- All rights reserved.
@@ -35,8 +35,7 @@ pgfs_clients AS (SELECT -count(*) FROM p
 	WHERE datname = current_database())),
 files_to_remove AS (DELETE FROM file WHERE nlink IN (SELECT * FROM pgfs_clients)
 	RETURNING fileid),
-removed_files AS (DELETE FROM datafork WHERE CASE WHEN fileid IN (SELECT * FROM
-	files_to_remove) THEN lo_unlink(loid) = 1 ELSE false END
-	RETURNING fileid)
-SELECT fileid AS "orphaned files" from removed_files;
+removed_files AS (DELETE FROM datafork WHERE fileid IN (SELECT * FROM
+	files_to_remove) RETURNING fileid, loid)
+SELECT fileid AS "orphaned files" FROM removed_files WHERE lo_unlink(loid) = 1;
 COMMIT;
Index: src/share/examples/puffs/pgfs/pgfs_subs.c
diff -u src/share/examples/puffs/pgfs/pgfs_subs.c:1.1 src/share/examples/puffs/pgfs/pgfs_subs.c:1.2
--- src/share/examples/puffs/pgfs/pgfs_subs.c:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/pgfs_subs.c	Wed Oct 12 16:24:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_subs.c,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: pgfs_subs.c,v 1.2 2011/10/12 16:24:39 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: pgfs_subs.c,v 1.1 2011/10/12 01:05:00 yamt Exp $");
+__RCSID("$NetBSD: pgfs_subs.c,v 1.2 2011/10/12 16:24:39 yamt Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -795,18 +795,24 @@ cleanupfile(struct Xconn *xc, fileid_t f
 
 	if (va->va_type == VREG || va->va_type == VLNK) {
 		static struct cmd *c_datafork;
+		int32_t ret;
 		int error;
 
-		/*
-		 * use CASE instead of AND to preserve the evaluation ordering.
-		 */
 		CREATECMD(c_datafork,
-			"DELETE FROM datafork WHERE CASE WHEN fileid = $1 "
-			"THEN lo_unlink(loid) = 1 ELSE false END", INT8OID);
-		error = simplecmd(xc, c_datafork, fileid);
+			"WITH loids AS (DELETE FROM datafork WHERE fileid = $1 "
+			"RETURNING loid) SELECT lo_unlink(loid) FROM loids",
+			INT8OID);
+		error = sendcmd(xc, c_datafork, fileid);
 		if (error != 0) {
 			return error;
 		}
+		error = simplefetch(xc, INT4OID, &ret);
+		if (error != 0) {
+			return error;
+		}
+		if (ret != 1) {
+			return EIO; /* lo_unlink failed */
+		}
 	}
 	CREATECMD(c, "DELETE FROM file WHERE fileid = $1", INT8OID);
 	return simplecmd(xc, c, fileid);

Reply via email to