*** pgsql/src/backend/commands/lockcmds.c 2009/01/01 17:23:38 1.20 --- pgsql/src/backend/commands/lockcmds.c 2009/01/12 08:54:26 1.21 *************** *** 8,14 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.19 2008/09/08 00:47:40 tgl Exp $ * *------------------------------------------------------------------------- */ --- 8,14 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.20 2009/01/01 17:23:38 momjian Exp $ * *------------------------------------------------------------------------- */ *************** *** 18,23 **** --- 18,25 ---- #include "catalog/namespace.h" #include "commands/lockcmds.h" #include "miscadmin.h" + #include "optimizer/prep.h" + #include "parser/parse_clause.h" #include "utils/acl.h" #include "utils/lsyscache.h" #include "utils/rel.h" *************** LockTableCommand(LockStmt *lockstmt) *** 40,77 **** { RangeVar *relation = lfirst(p); Oid reloid; ! AclResult aclresult; ! Relation rel; - /* - * We don't want to open the relation until we've checked privilege. - * So, manually get the relation OID. - */ reloid = RangeVarGetRelid(relation, false); ! if (lockstmt->mode == AccessShareLock) ! aclresult = pg_class_aclcheck(reloid, GetUserId(), ! ACL_SELECT); else ! aclresult = pg_class_aclcheck(reloid, GetUserId(), ! ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE); ! if (aclresult != ACLCHECK_OK) ! aclcheck_error(aclresult, ACL_KIND_CLASS, ! get_rel_name(reloid)); ! if (lockstmt->nowait) ! rel = relation_open_nowait(reloid, lockstmt->mode); ! else ! rel = relation_open(reloid, lockstmt->mode); ! ! /* Currently, we only allow plain tables to be locked */ ! if (rel->rd_rel->relkind != RELKIND_RELATION) ! ereport(ERROR, ! (errcode(ERRCODE_WRONG_OBJECT_TYPE), ! errmsg("\"%s\" is not a table", ! relation->relname))); ! ! relation_close(rel, NoLock); /* close rel, keep lock */ } } --- 42,89 ---- { RangeVar *relation = lfirst(p); Oid reloid; ! bool recurse = interpretInhOption(relation->inhOpt); ! List *children_and_self; ! ListCell *child; reloid = RangeVarGetRelid(relation, false); ! if (recurse) ! children_and_self = find_all_inheritors(reloid); else ! children_and_self = list_make1_oid(reloid); ! foreach(child, children_and_self) ! { ! Oid childreloid = lfirst_oid(child); ! Relation rel; ! AclResult aclresult; ! ! /* We don't want to open the relation until we've checked privilege. */ ! if (lockstmt->mode == AccessShareLock) ! aclresult = pg_class_aclcheck(childreloid, GetUserId(), ! ACL_SELECT); ! else ! aclresult = pg_class_aclcheck(childreloid, GetUserId(), ! ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE); ! ! if (aclresult != ACLCHECK_OK) ! aclcheck_error(aclresult, ACL_KIND_CLASS, ! get_rel_name(childreloid)); ! ! if (lockstmt->nowait) ! rel = relation_open_nowait(childreloid, lockstmt->mode); ! else ! rel = relation_open(childreloid, lockstmt->mode); ! ! /* Currently, we only allow plain tables to be locked */ ! if (rel->rd_rel->relkind != RELKIND_RELATION) ! ereport(ERROR, ! (errcode(ERRCODE_WRONG_OBJECT_TYPE), ! errmsg("\"%s\" is not a table", ! get_rel_name(childreloid)))); ! relation_close(rel, NoLock); /* close rel, keep lock */ ! } } }