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

📄 opt_remotequeries.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
	r= newInstruction(mb,ASSIGNsymbol);	getModuleId(r)= mserverRef;	getFunctionId(r)= rpcRef;	getArg(r,0)= newTmpVariable(mb, tpe);	pushArgument(mb,r,j);#line 341 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"				#line 222 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"	for(j=p->retc; j<p->argc; j++)	if( location[getArg(p,j)] == 0 && !isConstant(mb,getArg(p,j)) ){		q= newStmt(mb,mserverRef,putRef);		getArg(q,0)= newTmpVariable(mb, TYPE_void);		pushArgument(mb,q,location[getArg(p,j)]);		pushStr(mb,q, getRefName(mb,getArg(p,j)));		pushArgument(mb,q,getArg(p,j));	}#line 342 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"				#line 231 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"	s= RQcall2str(mb,p);	pushStr(mb,r,s+1);	GDKfree(s);	pushInstruction(mb,r);	freeInstruction(p);	doit++;#line 343 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"			} else				pushInstruction(mb,p);		} else		if(getModuleId(p)== sqlRef && getFunctionId(p)== binddbatRef) {			if( p->argc == 5 && getArgType(mb,p,3) == TYPE_str ) {				#line 192 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"	/* lookup the server connection */	if( location[getArg(p,0)] == 0){		db = 0;		if( isConstant(mb,getArg(p,3)) )			db= getVarConstant(mb, getArg(p,3)).val.sval;		for(k=0; k<dbtop; k++)			if( strcmp(db, dbalias[k].dbname)== 0)				break;				if( k== dbtop){			r= newInstruction(mb,ASSIGNsymbol);			getModuleId(r)= mserverRef;			getFunctionId(r)= lookupRef;			j= getArg(r,0)= newTmpVariable(mb, TYPE_int);			pushArgument(mb,r, getArg(p,3));			pushInstruction(mb,r);			dbalias[dbtop].dbhdl= j;			dbalias[dbtop++].dbname= db;			if( dbtop== 127) dbtop--;		} else j= dbalias[k].dbhdl;		location[getArg(p,0)]= j;	} else j= location[getArg(p,0)];#line 350 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"				/* turn the instruction into a local one */				getArg(p,3)= defConstant(mb, TYPE_int, &cst);				#line 215 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"	r= newInstruction(mb,ASSIGNsymbol);	getModuleId(r)= mserverRef;	getFunctionId(r)= rpcRef;	getArg(r,0)= newTmpVariable(mb, TYPE_void);	pushArgument(mb,r,j);#line 355 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"				#line 222 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"	for(j=p->retc; j<p->argc; j++)	if( location[getArg(p,j)] == 0 && !isConstant(mb,getArg(p,j)) ){		q= newStmt(mb,mserverRef,putRef);		getArg(q,0)= newTmpVariable(mb, TYPE_void);		pushArgument(mb,q,location[getArg(p,j)]);		pushStr(mb,q, getRefName(mb,getArg(p,j)));		pushArgument(mb,q,getArg(p,j));	}#line 356 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"				#line 231 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"	s= RQcall2str(mb,p);	pushStr(mb,r,s+1);	GDKfree(s);	pushInstruction(mb,r);	freeInstruction(p);	doit++;#line 357 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"			} else				pushInstruction(mb,p);#ifdef DEBUG_OPT_REMOTE			printf("found remote variable %s ad %d\n", 				getVarName(mb,getArg(p,0)), location[getArg(p,0)]);#endif		} else		if( getModuleId(p) && strcmp(getModuleId(p),"optimizer")==0 &&		    getFunctionId(p) && strcmp(getFunctionId(p),"remoteQueries")==0 )			freeInstruction(p);		else if (cnt == 0 || p->barrier) /* local only or flow control statement */			pushInstruction(mb,p);		else {#line 379 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"			remoteSite=0;			collectFirst= FALSE;			for(j=0; j<p->argc; j++)			if( location[getArg(p,j)]){				if (remoteSite == 0)					remoteSite= location[getArg(p,j)];				else if( remoteSite != location[getArg(p,j)])					collectFirst= TRUE;			}			if( getModuleId(p)== ioRef || (getModuleId(p)== sqlRef 		            && (getFunctionId(p)== resultSetRef ||				getFunctionId(p)== rsColumnRef)))				 collectFirst= TRUE; 			/* local BATs are not shipped */			if( remoteSite && collectFirst== FALSE)				for(j=p->retc; j<p->argc; j++)				if( location[getArg(p,j)] == 0 &&					isaBatType(getVarType(mb,getArg(p,j)))) 						collectFirst= TRUE;			if (collectFirst){				/* perform locally */				for(j=p->retc; j<p->argc; j++)				if( location[getArg(p,j)]){					q= newStmt(mb,mserverRef,rpcRef);					getArg(q,0)= getArg(p,j);					pushArgument(mb,q,location[getArg(p,j)]);					snprintf(buf,BUFSIZ,"io.print(%s);",						getRefName(mb,getArg(p,j)) );					pushStr(mb,q,buf);				}				pushInstruction(mb,p);				/* as of now all the targets are also local */				for(j=0; j<p->retc; j++)					location[getArg(p,j)]= 0;				doit++;			} else if (remoteSite){				/* single remote site involved */				r= newInstruction(mb,ASSIGNsymbol);				getModuleId(r)= mserverRef;				getFunctionId(r)= rpcRef;				getArg(r,0)= newTmpVariable(mb, TYPE_void);				pushArgument(mb, r, remoteSite);				for(j=p->retc; j<p->argc; j++)				if( location[getArg(p,j)] == 0 && !isConstant(mb,getArg(p,j)) ){					q= newStmt(mb,mserverRef,putRef);					getArg(q,0)= newTmpVariable(mb, TYPE_void);					pushArgument(mb, q, remoteSite);					pushStr(mb,q, getRefName(mb,getArg(p,j)));					pushArgument(mb, q, getArg(p,j));				}				s= RQcall2str(mb, p);				pushInstruction(mb,r);				pushStr(mb,r,s+1);				GDKfree(s);				for(j=0; j<p->retc; j++)					location[getArg(p,j)]= remoteSite;				freeInstruction(p);				doit++;			} else				pushInstruction(mb,p);		}	}	GDKfree(old);#ifdef DEBUG_OPT_REMOTE	if (doit) {		stream_printf(GDKout, "remoteQueries %d\n", doit);		printFunction(GDKout, mb, LIST_MAL_ALL);	}#endif	return doit;}#line 457 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"#line 455 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"/* #define _DEBUG_OPTIMIZER_*/str OPTremoteQueries(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	str modnme;	str fcnnme;	Module  scope=NULL;	Symbol s= NULL;	lng clk= GDKusec();	int actions = 0;	optimizerInit();	if( p )		removeInstruction(mb, p);#ifdef _DEBUG_OPTIMIZER_	stream_printf(GDKout,"apply remoteQueries\n");	printFunction(GDKout,mb,LIST_MAL_ALL);#endif	if( p && p->argc > 1 && getFunctionId(p) != multiplexRef){#ifdef _DEBUG_OPTIMIZER_		stream_printf(GDKout,"locate function remoteQueries\n");#endif		if( getArgType(mb,p,1) != TYPE_str ||			getArgType(mb,p,2) != TYPE_str ||			!isConstant(mb,getArg(p,1)) ||			!isConstant(mb,getArg(p,2))		) {			char buf[1024];			snprintf(buf,1024, "Optimizer requires constant string arguments\n");			throw(MAL, "optimizer.remoteQueries",buf);		}		if( stk != 0){			modnme= (str)getArgValue(stk,p,1);			fcnnme= (str)getArgValue(stk,p,2);		} else {			modnme= getArgDefault(mb,p,1);			fcnnme= getArgDefault(mb,p,2);		}		scope = findModule(MCgetClient()->nspace,putName(modnme,strlen(modnme)) );		if( scope)			s= findSymbolInModule(scope,putName(fcnnme,strlen(fcnnme)));		if( s == NULL) {			char buf[1024];			snprintf(buf,1024, "Could not find %s.%s\n",modnme,fcnnme);			throw(MAL, "optimizer.remoteQueries",buf);		}#ifdef _DEBUG_OPTIMIZER_		stream_printf(GDKout,"remoteQueries %s %d\n",modnme,fcnnme);#endif		mb = s->def;		stk= 0;	} 	if( mb->errors )		return MAL_SUCCEED;	addtoMalBlkHistory(mb);	actions= OPTremoteQueriesImplementation(mb,stk,p);#ifdef _DEBUG_OPTIMIZER_	stream_printf(GDKout,"finished remoteQueries %d\n",actions);	printFunction(GDKout,mb,LIST_MAL_ALL);#endif    optimizerCheck(mb, "optimizer.remoteQueries", actions, GDKusec() - clk,OPT_CHECK_ALL);	return MAL_SUCCEED;}#line 457 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"#line 459 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_remoteQueries.mx"

⌨️ 快捷键说明

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