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

📄 eval0eval.c

📁 这是linux下运行的mysql软件包,可用于linux 下安装 php + mysql + apach 的网络配置
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************SQL evaluator: evaluates simple data structures, like expressions, ina query graph(c) 1997 Innobase OyCreated 12/29/1997 Heikki Tuuri*******************************************************/#include "eval0eval.h"#ifdef UNIV_NONINL#include "eval0eval.ic"#endif#include "data0data.h"#include "row0sel.h"/* The RND function seed */ulint	eval_rnd 	= 128367121;/* Dummy adress used when we should allocate a buffer of size 0 inthe function below */byte	eval_dummy;/*********************************************************************Allocate a buffer from global dynamic memory for a value of a que_node.NOTE that this memory must be explicitly freed when the query graph isfreed. If the node already has an allocated buffer, that buffer is freedhere. NOTE that this is the only function where dynamic memory should beallocated for a query node val field. */byte*eval_node_alloc_val_buf(/*====================*/				/* out: pointer to allocated buffer */	que_node_t*	node,	/* in: query graph node; sets the val field				data field to point to the new buffer, and				len field equal to size */	ulint		size)	/* in: buffer size */{	dfield_t*	dfield;	byte*		data;	ut_ad(que_node_get_type(node) == QUE_NODE_SYMBOL	      || que_node_get_type(node) == QUE_NODE_FUNC);	dfield = que_node_get_val(node);	data = dfield_get_data(dfield);		if (data && data != &eval_dummy) {		mem_free(data);	}	if (size == 0) {		data = &eval_dummy;	} else {		data = mem_alloc(size);	}	que_node_set_val_buf_size(node, size);	dfield_set_data(dfield, data, size);	return(data);}/*********************************************************************Free the buffer from global dynamic memory for a value of a que_node,if it has been allocated in the above function. The freeing for pushedcolumn values is done in sel_col_prefetch_buf_free. */voideval_node_free_val_buf(/*===================*/	que_node_t*	node)	/* in: query graph node */{	dfield_t*	dfield;	byte*		data;	ut_ad(que_node_get_type(node) == QUE_NODE_SYMBOL	      || que_node_get_type(node) == QUE_NODE_FUNC);	dfield = que_node_get_val(node);	data = dfield_get_data(dfield);		if (que_node_get_val_buf_size(node) > 0) {		ut_a(data);			mem_free(data);	}}/*********************************************************************Evaluates a comparison node. */ibooleval_cmp(/*=====*/					/* out: the result of the comparison */	func_node_t*	cmp_node)	/* in: comparison node */{	que_node_t*	arg1;	que_node_t*	arg2;	int		res;	ibool		val;	int		func;		ut_ad(que_node_get_type(cmp_node) == QUE_NODE_FUNC);	arg1 = cmp_node->args;	arg2 = que_node_get_next(arg1);	res = cmp_dfield_dfield(que_node_get_val(arg1),						que_node_get_val(arg2));	val = TRUE;	func = cmp_node->func;				if (func == '=') {		if (res != 0) {			val = FALSE;		}	} else if (func == '<') {		if (res != -1) {			val = FALSE;		}	} else if (func == PARS_LE_TOKEN) {		if (res == 1) {			val = FALSE;		}	} else if (func == PARS_NE_TOKEN) {		if (res == 0) {			val = FALSE;		}	} else if (func == PARS_GE_TOKEN) {		if (res == -1) {			val = FALSE;		}	} else {		ut_ad(func == '>');				if (res != 1) {			val = FALSE;		}	}	eval_node_set_ibool_val(cmp_node, val);	return(val);}/*********************************************************************Evaluates a logical operation node. */UNIV_INLINEvoideval_logical(/*=========*/	func_node_t*	logical_node)	/* in: logical operation node */{	que_node_t*	arg1;	que_node_t*	arg2;	ibool		val1;	ibool		val2 = 0; /* remove warning */	ibool		val = 0;  /* remove warning */	int		func;	ut_ad(que_node_get_type(logical_node) == QUE_NODE_FUNC);	arg1 = logical_node->args;	arg2 = que_node_get_next(arg1); /* arg2 is NULL if func is 'NOT' */	val1 = eval_node_get_ibool_val(arg1);	if (arg2) {		val2 = eval_node_get_ibool_val(arg2);	}	func = logical_node->func;	if (func == PARS_AND_TOKEN) {		val = val1 & val2;	} else if (func == PARS_OR_TOKEN) {		val = val1 | val2;	} else if (func == PARS_NOT_TOKEN) {		val = TRUE - val1;	} else {		ut_error;	}	eval_node_set_ibool_val(logical_node, val);}/*********************************************************************Evaluates an arithmetic operation node. */UNIV_INLINEvoideval_arith(/*=======*/	func_node_t*	arith_node)	/* in: arithmetic operation node */{	que_node_t*	arg1;	que_node_t*	arg2;	lint		val1;	lint		val2 = 0; /* remove warning */	lint		val;	int		func;	ut_ad(que_node_get_type(arith_node) == QUE_NODE_FUNC);	arg1 = arith_node->args;	arg2 = que_node_get_next(arg1); /* arg2 is NULL if func is unary '-' */	val1 = eval_node_get_int_val(arg1);	if (arg2) {		val2 = eval_node_get_int_val(arg2);	}	func = arith_node->func;	if (func == '+') {		val = val1 + val2;	} else if ((func == '-') && arg2) {		val = val1 - val2;	} else if (func == '-') {		val = -val1;	} else if (func == '*') {		val = val1 * val2;	} else {		ut_ad(func == '/');		val = val1 / val2;	}	eval_node_set_int_val(arith_node, val);}/*********************************************************************Evaluates an aggregate operation node. */UNIV_INLINEvoideval_aggregate(/*===========*/	func_node_t*	node)	/* in: aggregate operation node */{	que_node_t*	arg;	lint		val;	lint		arg_val;	int		func;	ut_ad(que_node_get_type(node) == QUE_NODE_FUNC);	val = eval_node_get_int_val(node);	func = node->func;	if (func == PARS_COUNT_TOKEN) {		val = val + 1;	} else {		ut_ad(func == PARS_SUM_TOKEN);		arg = node->args;		arg_val = eval_node_get_int_val(arg);		val = val + arg_val;	}		eval_node_set_int_val(node, val);}/*********************************************************************Evaluates a predefined function node where the function is not relevantin benchmarks. */staticvoideval_predefined_2(/*==============*/	func_node_t*	func_node)	/* in: predefined function node */{	que_node_t*	arg;	que_node_t*	arg1;	que_node_t*	arg2 = 0; /* remove warning (??? bug ???) */	lint		int_val;	byte*		data;	ulint		len1;	ulint		len2;	int		func;	ulint		i;	ut_ad(que_node_get_type(func_node) == QUE_NODE_FUNC);	arg1 = func_node->args;	if (arg1) {		arg2 = que_node_get_next(arg1);	}	func = func_node->func;	if (func == PARS_PRINTF_TOKEN) {		arg = arg1;			while (arg) {			dfield_print(que_node_get_val(arg));			arg = que_node_get_next(arg);		}		putc('\n', stderr);			} else if (func == PARS_ASSERT_TOKEN) {		if (!eval_node_get_ibool_val(arg1)) {			fputs("SQL assertion fails in a stored procedure!\n",				stderr);		} 		ut_a(eval_node_get_ibool_val(arg1));				/* This function, or more precisely, a debug procedure,		returns no value */	} else if (func == PARS_RND_TOKEN) {		len1 = (ulint)eval_node_get_int_val(arg1);		len2 = (ulint)eval_node_get_int_val(arg2);		ut_ad(len2 >= len1);		if (len2 > len1) {					int_val = (lint)(len1 +					(eval_rnd % (len2 - len1 + 1)));		} else {			int_val = (lint)len1;		}		eval_rnd = ut_rnd_gen_next_ulint(eval_rnd);		eval_node_set_int_val(func_node, int_val);	} else if (func == PARS_RND_STR_TOKEN) {		len1 = (ulint)eval_node_get_int_val(arg1);		data = eval_node_ensure_val_buf(func_node, len1);		for (i = 0; i < len1; i++) {			data[i] = (byte)(97 + (eval_rnd % 3));			eval_rnd = ut_rnd_gen_next_ulint(eval_rnd);		}	} else {		ut_error;	}}/*********************************************************************Evaluates a notfound-function node. */UNIV_INLINEvoideval_notfound(/*==========*/	func_node_t*	func_node)	/* in: function node */{	que_node_t*	arg1;	que_node_t*	arg2;	sym_node_t*	cursor;	sel_node_t*	sel_node;	ibool		ibool_val;	arg1 = func_node->args;	arg2 = que_node_get_next(arg1);	ut_ad(func_node->func == PARS_NOTFOUND_TOKEN);	cursor = arg1;	ut_ad(que_node_get_type(cursor) == QUE_NODE_SYMBOL);	if (cursor->token_type == SYM_LIT) {				ut_ad(ut_memcmp(dfield_get_data(que_node_get_val(cursor)),							"SQL", 3) == 0);		sel_node = cursor->sym_table->query_graph->last_sel_node;	} else {		sel_node = cursor->alias->cursor_def;	}	if (sel_node->state == SEL_NODE_NO_MORE_ROWS) {		ibool_val = TRUE;	} else {		ibool_val = FALSE;	}	eval_node_set_ibool_val(func_node, ibool_val);}/*********************************************************************Evaluates a substr-function node. */UNIV_INLINEvoideval_substr(/*========*/	func_node_t*	func_node)	/* in: function node */{	que_node_t*	arg1;	que_node_t*	arg2;	que_node_t*	arg3;	dfield_t*	dfield;	byte*		str1;	ulint		len1;	ulint		len2;

⌨️ 快捷键说明

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