⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readfuncs.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 4 页
字号:
/*------------------------------------------------------------------------- * * readfuncs.c *	  Reader functions for Postgres tree nodes. * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $Header: /usr/local/cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.64 1999/05/25 16:09:11 momjian Exp $ * * NOTES *	  Most of the read functions for plan nodes are tested. (In fact, they *	  pass the regression test as of 11/8/94.) The rest (for path selection) *	  are probably never used. No effort has been made to get them to work. *	  The simplest way to test these functions is by doing the following in *	  ProcessQuery (before executing the plan): *				plan = stringToNode(nodeToString(plan)); *	  Then, run the regression test. Let's just say you'll notice if either *	  of the above function are not properly done. *														- ay 11/94 * *------------------------------------------------------------------------- */#include <stdio.h>#include <math.h>#include <string.h>#include "postgres.h"#include "access/heapam.h"#include "access/htup.h"#include "fmgr.h"#include "utils/builtins.h"#include "utils/elog.h"#include "utils/palloc.h"#include "utils/lsyscache.h"#include "utils/syscache.h"#include "catalog/pg_index.h"#include "catalog/pg_type.h"#include "nodes/primnodes.h"#include "nodes/plannodes.h"#include "nodes/parsenodes.h"#include "nodes/execnodes.h"#include "nodes/relation.h"#include "nodes/readfuncs.h"/* ---------------- *		node creator declarations * ---------------- */static Datum readDatum(Oid type);static List *toIntList(List *list){	List	   *l;	foreach(l, list)	{		/* ugly manipulation, should probably free the Value node too */		lfirst(l) = (void *) intVal(lfirst(l));	}	return list;}/* ---------------- *		_readQuery * ---------------- */static Query *_readQuery(){	Query	   *local_node;	char	   *token;	int			length;	local_node = makeNode(Query);	token = lsptok(NULL, &length);		/* skip the :command */	token = lsptok(NULL, &length);		/* get the commandType */	local_node->commandType = atoi(token);	token = lsptok(NULL, &length);		/* skip :utility */	/* we can't get create or index here, can we? */	token = lsptok(NULL, &length);		/* get the notify name if any */	if (length == 0)		local_node->utilityStmt = NULL;	else	{		NotifyStmt *n = makeNode(NotifyStmt);		n->relname = palloc(length + 1);		StrNCpy(n->relname, token, length + 1);		local_node->utilityStmt = (Node *) n;	}	token = lsptok(NULL, &length);		/* skip the :resultRelation */	token = lsptok(NULL, &length);		/* get the resultRelation */	local_node->resultRelation = atoi(token);	token = lsptok(NULL, &length);		/* skip :into */	token = lsptok(NULL, &length);		/* get into */	if (length == 0)		local_node->into = NULL;	else	{		local_node->into = palloc(length + 1);		StrNCpy(local_node->into, token, length + 1);	}	token = lsptok(NULL, &length);		/* skip :isPortal */	token = lsptok(NULL, &length);		/* get isPortal */	local_node->isPortal = (token[0] == 't') ? true : false;	token = lsptok(NULL, &length);		/* skip :isBinary */	token = lsptok(NULL, &length);		/* get isBinary */	local_node->isBinary = (token[0] == 't') ? true : false;	token = lsptok(NULL, &length);		/* skip :isTemp */	token = lsptok(NULL, &length);		/* get isTemp */	local_node->isTemp = (token[0] == 't') ? true : false;	token = lsptok(NULL, &length);		/* skip :unionall */	token = lsptok(NULL, &length);		/* get unionall */	local_node->unionall = (token[0] == 't') ? true : false;	token = lsptok(NULL, &length);		/* skip :uniqueFlag */	token = lsptok(NULL, &length);		/* get uniqueFlag */	if (length == 0)		local_node->uniqueFlag = NULL;	else	{		local_node->uniqueFlag = palloc(length + 1);		StrNCpy(local_node->uniqueFlag, token, length + 1);	}	token = lsptok(NULL, &length);		/* skip :sortClause */	local_node->sortClause = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :rtable */	local_node->rtable = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :targetlist */	local_node->targetList = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :qual */	local_node->qual = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :groupClause */	local_node->groupClause = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :havingQual */	local_node->havingQual = nodeRead(true);	token = lsptok(NULL, &length);		/* skip the :hasAggs */	token = lsptok(NULL, &length);		/* get hasAggs */	local_node->hasAggs = (token[0] == 't') ? true : false;	token = lsptok(NULL, &length);		/* skip the :hasSubLinks */	token = lsptok(NULL, &length);		/* get hasSubLinks */	local_node->hasSubLinks = (token[0] == 't') ? true : false;	token = lsptok(NULL, &length);		/* skip :unionClause */	local_node->unionClause = nodeRead(true);	/***S*I***/	token = lsptok(NULL, &length);		/* skip :intersectClause */	local_node->intersectClause = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :limitOffset */	local_node->limitOffset = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :limitCount */	local_node->limitCount = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :rowMark */	local_node->rowMark = nodeRead(true);	return local_node;}/* ---------------- *		_readSortClause * ---------------- */static SortClause *_readSortClause(){	SortClause *local_node;	char	   *token;	int			length;	local_node = makeNode(SortClause);	token = lsptok(NULL, &length);		/* skip the :resdom */	local_node->resdom = nodeRead(true);	token = lsptok(NULL, &length);		/* skip :opoid */	token = lsptok(NULL, &length);		/* get opoid */	local_node->opoid = strtoul(token, NULL, 10);	return local_node;}/* ---------------- *		_readGroupClause * ---------------- */static GroupClause *_readGroupClause(){	GroupClause *local_node;	char	   *token;	int			length;	local_node = makeNode(GroupClause);	token = lsptok(NULL, &length);		/* skip :grpOpoid */	token = lsptok(NULL, &length);		/* get grpOpoid */	local_node->grpOpoid = strtoul(token, NULL, 10);	token = lsptok(NULL, &length);		/* skip :tleGroupref */	token = lsptok(NULL, &length);		/* get tleGroupref */	local_node->tleGroupref = strtoul(token, NULL, 10);	return local_node;}/* ---------------- *		_getPlan * ---------------- */static void_getPlan(Plan *node){	char	   *token;	int			length;	token = lsptok(NULL, &length);		/* first token is :cost */	token = lsptok(NULL, &length);		/* next is the actual cost */	node->cost = (Cost) atof(token);	token = lsptok(NULL, &length);		/* skip the :size */	token = lsptok(NULL, &length);		/* get the plan_size */	node->plan_size = atoi(token);	token = lsptok(NULL, &length);		/* skip the :width */	token = lsptok(NULL, &length);		/* get the plan_width */	node->plan_width = atoi(token);	token = lsptok(NULL, &length);		/* eat the :state stuff */	token = lsptok(NULL, &length);		/* now get the state */	if (length == 0)		node->state = (EState *) NULL;	else	{							/* Disgusting hack until I figure out what								 * to do here */		node->state = (EState *) !NULL;	}	token = lsptok(NULL, &length);		/* eat :qptargetlist */	node->targetlist = nodeRead(true);	token = lsptok(NULL, &length);		/* eat :qpqual */	node->qual = nodeRead(true);	token = lsptok(NULL, &length);		/* eat :lefttree */	node->lefttree = (Plan *) nodeRead(true);	token = lsptok(NULL, &length);		/* eat :righttree */	node->righttree = (Plan *) nodeRead(true);	return;}/* *	Stuff from plannodes.h *//* ---------------- *		_readPlan * ---------------- */static Plan *_readPlan(){	Plan	   *local_node;	local_node = makeNode(Plan);	_getPlan(local_node);	return local_node;}/* ---------------- *		_readResult * *		Does some obscene, possibly unportable, magic with *		sizes of things. * ---------------- */static Result *_readResult(){	Result	   *local_node;	char	   *token;	int			length;	local_node = makeNode(Result);	_getPlan((Plan *) local_node);	token = lsptok(NULL, &length);		/* eat :resconstantqual */	local_node->resconstantqual = nodeRead(true);		/* now read it */	return local_node;}/* ---------------- *		_readAppend * *	Append is a subclass of Plan. * ---------------- */static Append *_readAppend(){	Append	   *local_node;	char	   *token;	int			length;	local_node = makeNode(Append);	_getPlan((Plan *) local_node);	token = lsptok(NULL, &length);		/* eat :appendplans */	local_node->appendplans = nodeRead(true);	/* now read it */	token = lsptok(NULL, &length);		/* eat :unionrtables */	local_node->unionrtables = nodeRead(true);	/* now read it */	token = lsptok(NULL, &length);		/* eat :inheritrelid */	token = lsptok(NULL, &length);		/* get inheritrelid */	local_node->inheritrelid = strtoul(token, NULL, 10);	token = lsptok(NULL, &length);		/* eat :inheritrtable */	local_node->inheritrtable = nodeRead(true); /* now read it */	return local_node;}/* ---------------- *		_getJoin * * In case Join is not the same structure as Plan someday. * ---------------- */static void_getJoin(Join *node){	_getPlan((Plan *) node);}/* ---------------- *		_readJoin * *	Join is a subclass of Plan * ---------------- */static Join *_readJoin(){	Join	   *local_node;	local_node = makeNode(Join);	_getJoin(local_node);	return local_node;}/* ---------------- *		_readNestLoop * *	NestLoop is a subclass of Join * ---------------- */static NestLoop *_readNestLoop(){	NestLoop   *local_node;	local_node = makeNode(NestLoop);	_getJoin((Join *) local_node);	return local_node;}/* ---------------- *		_readMergeJoin * *	MergeJoin is a subclass of Join * ---------------- */static MergeJoin *_readMergeJoin(){	MergeJoin  *local_node;	char	   *token;	int			length;	local_node = makeNode(MergeJoin);	_getJoin((Join *) local_node);	token = lsptok(NULL, &length);		/* eat :mergeclauses */	local_node->mergeclauses = nodeRead(true);	/* now read it */	return local_node;}/* ---------------- *		_readHashJoin * *	HashJoin is a subclass of Join. * ---------------- */static HashJoin *_readHashJoin(){	HashJoin   *local_node;	char	   *token;	int			length;	local_node = makeNode(HashJoin);	_getJoin((Join *) local_node);	token = lsptok(NULL, &length);		/* eat :hashclauses */	local_node->hashclauses = nodeRead(true);	/* now read it */	token = lsptok(NULL, &length);		/* eat :hashjoinop */	token = lsptok(NULL, &length);		/* get hashjoinop */	local_node->hashjoinop = strtoul(token, NULL, 10);	token = lsptok(NULL, &length);		/* eat :hashdone */	token = lsptok(NULL, &length);		/* eat hashdone */	local_node->hashdone = false;	return local_node;}/* ---------------- *		_getScan * *	Scan is a subclass of Node *	(Actually, according to the plannodes.h include file, it is a *	subclass of Plan.  This is why _getPlan is used here.) * *	Scan gets its own get function since stuff inherits it. * ---------------- */static void_getScan(Scan *node){	char	   *token;	int			length;	_getPlan((Plan *) node);	token = lsptok(NULL, &length);		/* eat :scanrelid */	token = lsptok(NULL, &length);		/* get scanrelid */	node->scanrelid = strtoul(token, NULL, 10);}/* ---------------- *		_readScan * * Scan is a subclass of Plan (Not Node, see above). * ---------------- */static Scan *_readScan(){	Scan	   *local_node;	local_node = makeNode(Scan);	_getScan(local_node);	return local_node;}/* ---------------- *		_readSeqScan * *	SeqScan is a subclass of Scan * ---------------- */static SeqScan *_readSeqScan(){	SeqScan    *local_node;	local_node = makeNode(SeqScan);	_getScan((Scan *) local_node);	return local_node;}/* ---------------- *		_readIndexScan * *	IndexScan is a subclass of Scan * ---------------- */static IndexScan *_readIndexScan(){	IndexScan  *local_node;	char	   *token;	int			length;	local_node = makeNode(IndexScan);	_getScan((Scan *) local_node);	token = lsptok(NULL, &length);		/* eat :indxid */	local_node->indxid = toIntList(nodeRead(true));		/* now read it */	token = lsptok(NULL, &length);		/* eat :indxqual */	local_node->indxqual = nodeRead(true);		/* now read it */	token = lsptok(NULL, &length);		/* eat :indxqualorig */	local_node->indxqualorig = nodeRead(true);	/* now read it */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -