1996-07-09 02:22:35 -04:00
|
|
|
%{
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
2002-04-27 17:24:34 -04:00
|
|
|
* bootparse.y
|
2006-03-06 20:03:12 -05:00
|
|
|
* yacc grammar for the "bootstrap" mode (BKI file format)
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
2010-01-02 11:58:17 -05:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
2010-02-07 15:48:13 -05:00
|
|
|
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.105 2010/02/07 20:48:09 tgl Exp $
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
1996-10-21 04:31:23 -04:00
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
2001-05-11 21:48:49 -04:00
|
|
|
#include <unistd.h>
|
1998-04-26 00:12:15 -04:00
|
|
|
|
1997-09-07 23:20:18 -04:00
|
|
|
#include "access/attnum.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "access/htup.h"
|
|
|
|
|
#include "access/itup.h"
|
|
|
|
|
#include "access/skey.h"
|
1997-09-07 23:20:18 -04:00
|
|
|
#include "access/tupdesc.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "access/xact.h"
|
|
|
|
|
#include "bootstrap/bootstrap.h"
|
2000-11-21 16:16:06 -05:00
|
|
|
#include "catalog/catalog.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "catalog/heap.h"
|
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
2014-02-17 09:33:31 -05:00
|
|
|
#include "catalog/namespace.h"
|
1997-09-07 23:20:18 -04:00
|
|
|
#include "catalog/pg_am.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "catalog/pg_attribute.h"
|
2005-08-25 23:08:15 -04:00
|
|
|
#include "catalog/pg_authid.h"
|
1996-10-21 04:31:23 -04:00
|
|
|
#include "catalog/pg_class.h"
|
2002-03-26 14:17:02 -05:00
|
|
|
#include "catalog/pg_namespace.h"
|
2004-06-18 02:14:31 -04:00
|
|
|
#include "catalog/pg_tablespace.h"
|
2006-07-30 21:16:38 -04:00
|
|
|
#include "catalog/toasting.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "commands/defrem.h"
|
1999-07-16 01:00:38 -04:00
|
|
|
#include "miscadmin.h"
|
2002-03-26 14:17:02 -05:00
|
|
|
#include "nodes/makefuncs.h"
|
1996-10-21 04:31:23 -04:00
|
|
|
#include "nodes/nodes.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "nodes/parsenodes.h"
|
|
|
|
|
#include "nodes/pg_list.h"
|
1998-04-07 14:14:38 -04:00
|
|
|
#include "nodes/primnodes.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "rewrite/prs2lock.h"
|
1996-10-21 04:31:23 -04:00
|
|
|
#include "storage/block.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "storage/fd.h"
|
1998-04-07 14:14:38 -04:00
|
|
|
#include "storage/ipc.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "storage/itemptr.h"
|
|
|
|
|
#include "storage/off.h"
|
1998-04-07 14:14:38 -04:00
|
|
|
#include "storage/smgr.h"
|
1996-10-21 04:31:23 -04:00
|
|
|
#include "tcop/dest.h"
|
1998-04-26 00:12:15 -04:00
|
|
|
#include "utils/rel.h"
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2005-04-13 21:38:22 -04:00
|
|
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
|
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2008-09-02 16:37:55 -04:00
|
|
|
/*
|
|
|
|
|
* Bison doesn't allocate anything that needs to live across parser calls,
|
|
|
|
|
* so we can easily have it use palloc instead of malloc. This prevents
|
|
|
|
|
* memory leaks if we error out during parsing. Note this only works with
|
|
|
|
|
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
|
|
|
|
|
* if possible, so there's not really much problem anyhow, at least if
|
|
|
|
|
* you're building with gcc.
|
|
|
|
|
*/
|
|
|
|
|
#define YYMALLOC palloc
|
|
|
|
|
#define YYFREE pfree
|
|
|
|
|
|
2001-05-11 21:48:49 -04:00
|
|
|
static void
|
2004-10-10 19:37:45 -04:00
|
|
|
do_start(void)
|
2001-05-11 21:48:49 -04:00
|
|
|
{
|
2003-05-13 23:26:03 -04:00
|
|
|
StartTransactionCommand();
|
2003-05-27 13:49:47 -04:00
|
|
|
elog(DEBUG4, "start transaction");
|
2001-05-11 21:48:49 -04:00
|
|
|
}
|
|
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2001-05-11 21:48:49 -04:00
|
|
|
static void
|
2004-10-10 19:37:45 -04:00
|
|
|
do_end(void)
|
2001-05-11 21:48:49 -04:00
|
|
|
{
|
2003-05-13 23:26:03 -04:00
|
|
|
CommitTransactionCommand();
|
2003-05-27 13:49:47 -04:00
|
|
|
elog(DEBUG4, "commit transaction");
|
2003-11-14 13:19:45 -05:00
|
|
|
CHECK_FOR_INTERRUPTS(); /* allow SIGINT to kill bootstrap run */
|
2001-05-11 21:48:49 -04:00
|
|
|
if (isatty(0))
|
|
|
|
|
{
|
|
|
|
|
printf("bootstrap> ");
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
static int num_columns_read = 0;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
2008-11-26 03:45:12 -05:00
|
|
|
%expect 0
|
2014-05-28 19:29:53 -04:00
|
|
|
%name-prefix="boot_yy"
|
2006-03-06 20:03:12 -05:00
|
|
|
|
1997-09-07 23:20:18 -04:00
|
|
|
%union
|
|
|
|
|
{
|
|
|
|
|
List *list;
|
|
|
|
|
IndexElem *ielem;
|
|
|
|
|
char *str;
|
|
|
|
|
int ival;
|
2001-05-11 21:48:49 -04:00
|
|
|
Oid oidval;
|
1996-07-09 02:22:35 -04:00
|
|
|
}
|
|
|
|
|
|
1998-08-18 22:04:17 -04:00
|
|
|
%type <list> boot_index_params
|
|
|
|
|
%type <ielem> boot_index_param
|
2009-09-26 21:32:11 -04:00
|
|
|
%type <str> boot_const boot_ident
|
2002-04-27 17:24:34 -04:00
|
|
|
%type <ival> optbootstrap optsharedrelation optwithoutoids
|
2009-09-26 18:42:03 -04:00
|
|
|
%type <oidval> oidspec optoideq optrowtypeoid
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
%token <str> CONST_P ID
|
1996-07-09 02:22:35 -04:00
|
|
|
%token OPEN XCLOSE XCREATE INSERT_TUPLE
|
2006-07-30 21:16:38 -04:00
|
|
|
%token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE XTOAST
|
1996-07-09 02:22:35 -04:00
|
|
|
%token COMMA EQUALS LPAREN RPAREN
|
2009-09-26 18:42:03 -04:00
|
|
|
%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS XROWTYPE_OID NULLVAL
|
2009-09-26 21:32:11 -04:00
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
%start TopLevel
|
|
|
|
|
|
|
|
|
|
%nonassoc low
|
|
|
|
|
%nonassoc high
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
TopLevel:
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_Queries
|
1997-09-07 23:20:18 -04:00
|
|
|
|
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_Queries:
|
|
|
|
|
Boot_Query
|
|
|
|
|
| Boot_Queries Boot_Query
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_Query :
|
|
|
|
|
Boot_OpenStmt
|
|
|
|
|
| Boot_CloseStmt
|
|
|
|
|
| Boot_CreateStmt
|
|
|
|
|
| Boot_InsertStmt
|
|
|
|
|
| Boot_DeclareIndexStmt
|
1999-11-04 03:01:09 -05:00
|
|
|
| Boot_DeclareUniqueIndexStmt
|
2006-07-30 21:16:38 -04:00
|
|
|
| Boot_DeclareToastStmt
|
1998-01-06 13:53:02 -05:00
|
|
|
| Boot_BuildIndsStmt
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
|
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_OpenStmt:
|
|
|
|
|
OPEN boot_ident
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_openrel($2);
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_CloseStmt:
|
|
|
|
|
XCLOSE boot_ident %prec low
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
2009-09-26 21:32:11 -04:00
|
|
|
closerel($2);
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
| XCLOSE %prec high
|
|
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
1997-09-07 23:20:18 -04:00
|
|
|
closerel(NULL);
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_CreateStmt:
|
2009-09-26 18:42:03 -04:00
|
|
|
XCREATE boot_ident oidspec optbootstrap optsharedrelation optwithoutoids optrowtypeoid LPAREN
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
|
|
|
|
numattr = 0;
|
2005-04-13 21:38:22 -04:00
|
|
|
elog(DEBUG4, "creating%s%s relation %s %u",
|
2009-09-26 18:42:03 -04:00
|
|
|
$4 ? " bootstrap" : "",
|
|
|
|
|
$5 ? " shared" : "",
|
2009-09-26 21:32:11 -04:00
|
|
|
$2,
|
2009-09-26 18:42:03 -04:00
|
|
|
$3);
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_column_list
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
RPAREN
|
|
|
|
|
{
|
2002-09-01 21:05:06 -04:00
|
|
|
TupleDesc tupdesc;
|
2010-02-07 15:48:13 -05:00
|
|
|
bool shared_relation;
|
|
|
|
|
bool mapped_relation;
|
2002-09-01 21:05:06 -04:00
|
|
|
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
1997-09-07 23:20:18 -04:00
|
|
|
|
2009-09-26 18:42:03 -04:00
|
|
|
tupdesc = CreateTupleDesc(numattr, !($6), attrtypes);
|
2002-09-01 21:05:06 -04:00
|
|
|
|
2010-02-07 15:48:13 -05:00
|
|
|
shared_relation = $5;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The catalogs that use the relation mapper are the
|
|
|
|
|
* bootstrap catalogs plus the shared catalogs. If this
|
|
|
|
|
* ever gets more complicated, we should invent a BKI
|
|
|
|
|
* keyword to mark the mapped catalogs, but for now a
|
|
|
|
|
* quick hack seems the most appropriate thing. Note in
|
|
|
|
|
* particular that all "nailed" heap rels (see formrdesc
|
|
|
|
|
* in relcache.c) must be mapped.
|
|
|
|
|
*/
|
|
|
|
|
mapped_relation = ($4 || shared_relation);
|
|
|
|
|
|
2009-09-26 18:42:03 -04:00
|
|
|
if ($4)
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2002-04-27 17:24:34 -04:00
|
|
|
if (boot_reldesc)
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2003-05-27 13:49:47 -04:00
|
|
|
elog(DEBUG4, "create bootstrap: warning, open relation exists, closing first");
|
1997-09-07 23:20:18 -04:00
|
|
|
closerel(NULL);
|
|
|
|
|
}
|
2001-05-11 21:48:49 -04:00
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_reldesc = heap_create($2,
|
2002-04-27 17:24:34 -04:00
|
|
|
PG_CATALOG_NAMESPACE,
|
2010-02-07 15:48:13 -05:00
|
|
|
shared_relation ? GLOBALTABLESPACE_OID : 0,
|
2009-09-26 18:42:03 -04:00
|
|
|
$3,
|
2002-04-27 17:24:34 -04:00
|
|
|
tupdesc,
|
2004-08-31 13:10:36 -04:00
|
|
|
RELKIND_RELATION,
|
2010-02-07 15:48:13 -05:00
|
|
|
shared_relation,
|
|
|
|
|
mapped_relation,
|
2002-04-27 17:24:34 -04:00
|
|
|
true);
|
2003-05-27 13:49:47 -04:00
|
|
|
elog(DEBUG4, "bootstrap relation created");
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Oid id;
|
|
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
id = heap_create_with_catalog($2,
|
2002-03-26 14:17:02 -05:00
|
|
|
PG_CATALOG_NAMESPACE,
|
2010-02-07 15:48:13 -05:00
|
|
|
shared_relation ? GLOBALTABLESPACE_OID : 0,
|
2009-09-26 18:42:03 -04:00
|
|
|
$3,
|
|
|
|
|
$7,
|
2010-01-28 18:21:13 -05:00
|
|
|
InvalidOid,
|
2005-08-25 23:08:15 -04:00
|
|
|
BOOTSTRAP_SUPERUSERID,
|
2000-07-04 02:11:54 -04:00
|
|
|
tupdesc,
|
2008-05-09 19:32:05 -04:00
|
|
|
NIL,
|
2000-07-04 02:11:54 -04:00
|
|
|
RELKIND_RELATION,
|
2010-02-07 15:48:13 -05:00
|
|
|
shared_relation,
|
|
|
|
|
mapped_relation,
|
2004-03-23 14:35:17 -05:00
|
|
|
true,
|
|
|
|
|
0,
|
2002-11-11 17:19:25 -05:00
|
|
|
ONCOMMIT_NOOP,
|
2006-07-03 18:45:41 -04:00
|
|
|
(Datum) 0,
|
2009-10-05 15:24:49 -04:00
|
|
|
false,
|
2006-07-03 18:45:41 -04:00
|
|
|
true);
|
2003-05-27 13:49:47 -04:00
|
|
|
elog(DEBUG4, "relation created with oid %u", id);
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_InsertStmt:
|
1997-09-07 23:20:18 -04:00
|
|
|
INSERT_TUPLE optoideq
|
|
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
Commit to match discussed elog() changes. Only update is that LOG is
now just below FATAL in server_min_messages. Added more text to
highlight ordering difference between it and client_min_messages.
---------------------------------------------------------------------------
REALLYFATAL => PANIC
STOP => PANIC
New INFO level the prints to client by default
New LOG level the prints to server log by default
Cause VACUUM information to print only to the client
NOTICE => INFO where purely information messages are sent
DEBUG => LOG for purely server status messages
DEBUG removed, kept as backward compatible
DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1 added
DebugLvl removed in favor of new DEBUG[1-5] symbols
New server_min_messages GUC parameter with values:
DEBUG[5-1], INFO, NOTICE, ERROR, LOG, FATAL, PANIC
New client_min_messages GUC parameter with values:
DEBUG[5-1], LOG, INFO, NOTICE, ERROR, FATAL, PANIC
Server startup now logged with LOG instead of DEBUG
Remove debug_level GUC parameter
elog() numbers now start at 10
Add test to print error message if older elog() values are passed to elog()
Bootstrap mode now has a -d that requires an argument, like postmaster
2002-03-02 16:39:36 -05:00
|
|
|
if ($2)
|
2003-07-22 19:30:39 -04:00
|
|
|
elog(DEBUG4, "inserting row with oid %u", $2);
|
Commit to match discussed elog() changes. Only update is that LOG is
now just below FATAL in server_min_messages. Added more text to
highlight ordering difference between it and client_min_messages.
---------------------------------------------------------------------------
REALLYFATAL => PANIC
STOP => PANIC
New INFO level the prints to client by default
New LOG level the prints to server log by default
Cause VACUUM information to print only to the client
NOTICE => INFO where purely information messages are sent
DEBUG => LOG for purely server status messages
DEBUG removed, kept as backward compatible
DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1 added
DebugLvl removed in favor of new DEBUG[1-5] symbols
New server_min_messages GUC parameter with values:
DEBUG[5-1], INFO, NOTICE, ERROR, LOG, FATAL, PANIC
New client_min_messages GUC parameter with values:
DEBUG[5-1], LOG, INFO, NOTICE, ERROR, FATAL, PANIC
Server startup now logged with LOG instead of DEBUG
Remove debug_level GUC parameter
elog() numbers now start at 10
Add test to print error message if older elog() values are passed to elog()
Bootstrap mode now has a -d that requires an argument, like postmaster
2002-03-02 16:39:36 -05:00
|
|
|
else
|
2003-07-22 19:30:39 -04:00
|
|
|
elog(DEBUG4, "inserting row");
|
2001-05-11 21:48:49 -04:00
|
|
|
num_columns_read = 0;
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
2009-09-26 21:32:11 -04:00
|
|
|
LPAREN boot_column_val_list RPAREN
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2001-05-11 21:48:49 -04:00
|
|
|
if (num_columns_read != numattr)
|
|
|
|
|
elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
|
|
|
|
|
numattr, num_columns_read);
|
2004-01-07 13:56:30 -05:00
|
|
|
if (boot_reldesc == NULL)
|
2007-03-07 08:35:03 -05:00
|
|
|
elog(FATAL, "relation not open");
|
2001-08-10 14:57:42 -04:00
|
|
|
InsertOneTuple($2);
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_DeclareIndexStmt:
|
2005-04-13 21:38:22 -04:00
|
|
|
XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
2014-02-17 09:33:31 -05:00
|
|
|
Oid relationId;
|
|
|
|
|
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
1996-07-09 02:22:35 -04:00
|
|
|
|
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
2014-02-17 09:33:31 -05:00
|
|
|
relationId = RangeVarGetRelid(makeRangeVar(NULL, $6, -1),
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
DefineIndex(relationId,
|
2009-09-26 21:32:11 -04:00
|
|
|
$3,
|
2005-04-13 21:38:22 -04:00
|
|
|
$4,
|
2009-09-26 21:32:11 -04:00
|
|
|
$8,
|
2004-06-18 02:14:31 -04:00
|
|
|
NULL,
|
2005-04-13 21:38:22 -04:00
|
|
|
$10,
|
2009-12-07 00:22:23 -05:00
|
|
|
NULL, NIL, NIL,
|
2009-07-29 16:56:21 -04:00
|
|
|
false, false, false, false, false,
|
2006-08-25 00:06:58 -04:00
|
|
|
false, false, true, false, false);
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1999-11-04 03:01:09 -05:00
|
|
|
Boot_DeclareUniqueIndexStmt:
|
2005-04-13 21:38:22 -04:00
|
|
|
XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
|
1999-11-04 03:01:09 -05:00
|
|
|
{
|
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
2014-02-17 09:33:31 -05:00
|
|
|
Oid relationId;
|
|
|
|
|
|
2001-05-11 21:48:49 -04:00
|
|
|
do_start();
|
1999-11-04 03:01:09 -05:00
|
|
|
|
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
2014-02-17 09:33:31 -05:00
|
|
|
relationId = RangeVarGetRelid(makeRangeVar(NULL, $7, -1),
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
DefineIndex(relationId,
|
2009-09-26 21:32:11 -04:00
|
|
|
$4,
|
2005-04-13 21:38:22 -04:00
|
|
|
$5,
|
2009-09-26 21:32:11 -04:00
|
|
|
$9,
|
2004-06-18 02:14:31 -04:00
|
|
|
NULL,
|
2005-04-13 21:38:22 -04:00
|
|
|
$11,
|
2009-12-07 00:22:23 -05:00
|
|
|
NULL, NIL, NIL,
|
2009-07-29 16:56:21 -04:00
|
|
|
true, false, false, false, false,
|
2006-08-25 00:06:58 -04:00
|
|
|
false, false, true, false, false);
|
2001-05-11 21:48:49 -04:00
|
|
|
do_end();
|
1999-11-04 03:01:09 -05:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2006-07-30 21:16:38 -04:00
|
|
|
Boot_DeclareToastStmt:
|
|
|
|
|
XDECLARE XTOAST oidspec oidspec ON boot_ident
|
|
|
|
|
{
|
|
|
|
|
do_start();
|
|
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
BootstrapToastTable($6, $3, $4);
|
2006-07-30 21:16:38 -04:00
|
|
|
do_end();
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
Boot_BuildIndsStmt:
|
2004-07-16 23:32:14 -04:00
|
|
|
XBUILD INDICES
|
|
|
|
|
{
|
|
|
|
|
do_start();
|
|
|
|
|
build_indices();
|
|
|
|
|
do_end();
|
|
|
|
|
}
|
2002-04-01 09:22:41 -05:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-08-18 22:04:17 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
boot_index_params:
|
1998-08-18 22:04:17 -04:00
|
|
|
boot_index_params COMMA boot_index_param { $$ = lappend($1, $3); }
|
2004-05-26 00:41:50 -04:00
|
|
|
| boot_index_param { $$ = list_make1($1); }
|
1998-08-18 22:04:17 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-08-18 22:04:17 -04:00
|
|
|
boot_index_param:
|
|
|
|
|
boot_ident boot_ident
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
|
|
|
|
IndexElem *n = makeNode(IndexElem);
|
2009-09-26 21:32:11 -04:00
|
|
|
n->name = $1;
|
2003-05-28 12:04:02 -04:00
|
|
|
n->expr = NULL;
|
Adjust naming of indexes and their columns per recent discussion.
Index expression columns are now named after the FigureColname result for
their expressions, rather than always being "pg_expression_N". Digits are
appended to this name if needed to make the column name unique within the
index. (That happens for regular columns too, thus fixing the old problem
that CREATE INDEX fooi ON foo (f1, f1) fails. Before exclusion indexes
there was no real reason to do such a thing, but now maybe there is.)
Default names for indexes and associated constraints now include the column
names of all their columns, not only the first one as in previous practice.
(Of course, this will be truncated as needed to fit in NAMEDATALEN. Also,
pkey indexes retain the historical behavior of not naming specific columns
at all.)
An example of the results:
regression=# create table foo (f1 int, f2 text,
regression(# exclude (f1 with =, lower(f2) with =));
NOTICE: CREATE TABLE / EXCLUDE will create implicit index "foo_f1_lower_exclusion" for table "foo"
CREATE TABLE
regression=# \d foo_f1_lower_exclusion
Index "public.foo_f1_lower_exclusion"
Column | Type | Definition
--------+---------+------------
f1 | integer | f1
lower | text | lower(f2)
btree, for table "public.foo"
2009-12-22 21:35:25 -05:00
|
|
|
n->indexcolname = NULL;
|
2009-09-26 21:32:11 -04:00
|
|
|
n->opclass = list_make1(makeString($2));
|
2007-01-08 21:14:16 -05:00
|
|
|
n->ordering = SORTBY_DEFAULT;
|
|
|
|
|
n->nulls_ordering = SORTBY_NULLS_DEFAULT;
|
1997-09-07 23:20:18 -04:00
|
|
|
$$ = n;
|
|
|
|
|
}
|
2002-04-01 09:22:41 -05:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
|
|
|
|
optbootstrap:
|
1997-09-07 23:20:18 -04:00
|
|
|
XBOOTSTRAP { $$ = 1; }
|
|
|
|
|
| { $$ = 0; }
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2002-04-27 17:24:34 -04:00
|
|
|
optsharedrelation:
|
|
|
|
|
XSHARED_RELATION { $$ = 1; }
|
|
|
|
|
| { $$ = 0; }
|
|
|
|
|
;
|
|
|
|
|
|
2001-08-10 14:57:42 -04:00
|
|
|
optwithoutoids:
|
|
|
|
|
XWITHOUT_OIDS { $$ = 1; }
|
|
|
|
|
| { $$ = 0; }
|
|
|
|
|
;
|
|
|
|
|
|
2009-09-26 18:42:03 -04:00
|
|
|
optrowtypeoid:
|
|
|
|
|
XROWTYPE_OID oidspec { $$ = $2; }
|
|
|
|
|
| { $$ = InvalidOid; }
|
|
|
|
|
;
|
|
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_column_list:
|
|
|
|
|
boot_column_def
|
|
|
|
|
| boot_column_list COMMA boot_column_def
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_column_def:
|
1998-01-06 13:53:02 -05:00
|
|
|
boot_ident EQUALS boot_ident
|
1997-09-07 23:20:18 -04:00
|
|
|
{
|
2003-07-22 19:30:39 -04:00
|
|
|
if (++numattr > MAXATTR)
|
2001-05-11 21:48:49 -04:00
|
|
|
elog(FATAL, "too many columns");
|
2009-09-26 21:32:11 -04:00
|
|
|
DefineAttr($1, $3, numattr-1);
|
1997-09-07 23:20:18 -04:00
|
|
|
}
|
|
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2005-04-13 21:38:22 -04:00
|
|
|
oidspec:
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_ident { $$ = atooid($1); }
|
2005-04-13 21:38:22 -04:00
|
|
|
;
|
|
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
optoideq:
|
2005-04-13 21:38:22 -04:00
|
|
|
OBJ_ID EQUALS oidspec { $$ = $3; }
|
2009-09-26 18:42:03 -04:00
|
|
|
| { $$ = InvalidOid; }
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_column_val_list:
|
|
|
|
|
boot_column_val
|
|
|
|
|
| boot_column_val_list boot_column_val
|
|
|
|
|
| boot_column_val_list COMMA boot_column_val
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2009-09-26 21:32:11 -04:00
|
|
|
boot_column_val:
|
2001-08-10 14:57:42 -04:00
|
|
|
boot_ident
|
2009-09-26 21:32:11 -04:00
|
|
|
{ InsertOneValue($1, num_columns_read++); }
|
2001-08-10 14:57:42 -04:00
|
|
|
| boot_const
|
2009-09-26 21:32:11 -04:00
|
|
|
{ InsertOneValue($1, num_columns_read++); }
|
1997-09-07 23:20:18 -04:00
|
|
|
| NULLVAL
|
2001-05-11 21:48:49 -04:00
|
|
|
{ InsertOneNull(num_columns_read++); }
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
|
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
boot_const :
|
2009-09-26 21:32:11 -04:00
|
|
|
CONST_P { $$ = yylval.str; }
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
|
1998-01-06 13:53:02 -05:00
|
|
|
boot_ident :
|
2009-09-26 21:32:11 -04:00
|
|
|
ID { $$ = yylval.str; }
|
1997-09-07 23:20:18 -04:00
|
|
|
;
|
1996-07-09 02:22:35 -04:00
|
|
|
%%
|
2002-11-01 17:52:34 -05:00
|
|
|
|
|
|
|
|
#include "bootscanner.c"
|