jsquery_extract.c
static void
processGroup(ExtractedNode *node, int start, int end)
{
	int					i;
	JsQueryItem		   *leftBound = NULL,
					   *rightBound = NULL,
					   *exactValue = NULL;
	bool				leftInclusive = false,
						rightInclusive = false,
						first = true;
	ExtractedNode	   *child;
	ExtractedNodeType	type = eAny;
	JsQueryItemType		isType = jqiNull;

	if (end - start < 2)
		return;

	for (i = start; i < end; i++)
	{
		int cmp;

		child = node->args.items[i];

		if (first || child->type <= type)
		{
			type = child->type;
			first = false;
			Assert(!isLogicalNodeType(type));
			switch(type)
			{
				case eAny:
				case eEmptyArray:
					break;
				case eIs:
					isType = child->isType;
					break;
				case eInequality:
					if (child->bounds.leftBound)
					{
						if (!leftBound)
						{
							leftBound = child->bounds.leftBound;
							leftInclusive = child->bounds.leftInclusive;
						}
						cmp = compareJsQueryItem(child->bounds.leftBound,
																	leftBound);
						if (cmp > 0)
						{
							leftBound = child->bounds.leftBound;
							leftInclusive = child->bounds.leftInclusive;
						}
						if (cmp == 0 && leftInclusive)
						{
							leftInclusive = child->bounds.leftInclusive;
						}
					}
					if (child->bounds.rightBound)
					{
						if (!rightBound)
						{
							rightBound = child->bounds.rightBound;
							rightInclusive = child->bounds.rightInclusive;
						}
						cmp = compareJsQueryItem(child->bounds.rightBound,
																	rightBound);
						if (cmp > 0)
						{
							rightBound = child->bounds.rightBound;
							rightInclusive = child->bounds.rightInclusive;
						}
						if (cmp == 0 && rightInclusive)
						{
							rightInclusive = child->bounds.rightInclusive;
						}
					}
					break;
				case eExactValue:
					exactValue = child->exactValue;
					break;
				default:
					elog(ERROR, "Wrong state");
					break;

			}
		}
	}

	child = node->args.items[start];
	child->type = type;

	switch(type)
	{
		case eAny:
		case eEmptyArray:
			break;
		case eIs:
			child->isType = isType;
			break;
		case eInequality:
			child->bounds.leftBound = leftBound;
			child->bounds.rightBound = rightBound;
			child->bounds.leftInclusive = leftInclusive;
			child->bounds.rightInclusive = rightInclusive;
			break;
		case eExactValue:
			child->exactValue = exactValue;
			break;
		default:
			elog(ERROR, "Wrong state");
			break;
	}

	for (i = start + 1; i < end; i++)
		node->args.items[i] = NULL;
}
/*
 * Process group of nodes representing conditions for the same field. After
 * processing group of nodes is replaced with one node.
 */
Process group of nodes representing conditions for the same field. After
processing group of nodes is replaced with one node.
Process group of nodes representing conditions for the same field . After processing group of nodes is replaced with one node .
static void
processGroup(ExtractedNode *node, int start, int end)
{
	int					i;
	JsQueryItem		   *leftBound = NULL,
					   *rightBound = NULL,
					   *exactValue = NULL;
	bool				leftInclusive = false,
						rightInclusive = false,
						first = true;
	ExtractedNode	   *child;
	ExtractedNodeType	type = eAny;
	JsQueryItemType		isType = jqiNull;
	if (end - start < 2)
		return;
	for (i = start; i < end; i++)
	{
		int cmp;
		child = node->args.items[i];
		if (first || child->type <= type)
		{
			type = child->type;
			first = false;
			Assert(!isLogicalNodeType(type));
			switch(type)
			{
				case eAny:
				case eEmptyArray:
					break;
				case eIs:
					isType = child->isType;
					break;
				case eInequality:
					if (child->bounds.leftBound)
					{
						if (!leftBound)
						{
							leftBound = child->bounds.leftBound;
							leftInclusive = child->bounds.leftInclusive;
						}
						cmp = compareJsQueryItem(child->bounds.leftBound,
																	leftBound);
						if (cmp > 0)
						{
							leftBound = child->bounds.leftBound;
							leftInclusive = child->bounds.leftInclusive;
						}
						if (cmp == 0 && leftInclusive)
						{
							leftInclusive = child->bounds.leftInclusive;
						}
					}
					if (child->bounds.rightBound)
					{
						if (!rightBound)
						{
							rightBound = child->bounds.rightBound;
							rightInclusive = child->bounds.rightInclusive;
						}
						cmp = compareJsQueryItem(child->bounds.rightBound,
																	rightBound);
						if (cmp > 0)
						{
							rightBound = child->bounds.rightBound;
							rightInclusive = child->bounds.rightInclusive;
						}
						if (cmp == 0 && rightInclusive)
						{
							rightInclusive = child->bounds.rightInclusive;
						}
					}
					break;
				case eExactValue:
					exactValue = child->exactValue;
					break;
				default:
					elog(ERROR, "Wrong state");
					break;
			}
		}
	}
	child = node->args.items[start];
	child->type = type;
	switch(type)
	{
		case eAny:
		case eEmptyArray:
			break;
		case eIs:
			child->isType = isType;
			break;
		case eInequality:
			child->bounds.leftBound = leftBound;
			child->bounds.rightBound = rightBound;
			child->bounds.leftInclusive = leftInclusive;
			child->bounds.rightInclusive = rightInclusive;
			break;
		case eExactValue:
			child->exactValue = exactValue;
			break;
		default:
			elog(ERROR, "Wrong state");
			break;
	}
	for (i = start + 1; i < end; i++)
		node->args.items[i] = NULL;
}
static void processGroup ( ExtractedNode * node , int start , int end ) { int i ; JsQueryItem * leftBound = NULL , * rightBound = NULL , * exactValue = NULL ; bool leftInclusive = false , rightInclusive = false , first = true ; ExtractedNode * child ; ExtractedNodeType type = eAny ; JsQueryItemType isType = jqiNull ; if ( end - start < 2 ) return ; for ( i = start ; i < end ; i ++ ) { int cmp ; child = node -> args . items [ i ] ; if ( first || child -> type <= type ) { type = child -> type ; first = false ; Assert ( ! isLogicalNodeType ( type ) ) ; switch ( type ) { case eAny : case eEmptyArray : break ; case eIs : isType = child -> isType ; break ; case eInequality : if ( child -> bounds . leftBound ) { if ( ! leftBound ) { leftBound = child -> bounds . leftBound ; leftInclusive = child -> bounds . leftInclusive ; } cmp = compareJsQueryItem ( child -> bounds . leftBound , leftBound ) ; if ( cmp > 0 ) { leftBound = child -> bounds . leftBound ; leftInclusive = child -> bounds . leftInclusive ; } if ( cmp == 0 && leftInclusive ) { leftInclusive = child -> bounds . leftInclusive ; } } if ( child -> bounds . rightBound ) { if ( ! rightBound ) { rightBound = child -> bounds . rightBound ; rightInclusive = child -> bounds . rightInclusive ; } cmp = compareJsQueryItem ( child -> bounds . rightBound , rightBound ) ; if ( cmp > 0 ) { rightBound = child -> bounds . rightBound ; rightInclusive = child -> bounds . rightInclusive ; } if ( cmp == 0 && rightInclusive ) { rightInclusive = child -> bounds . rightInclusive ; } } break ; case eExactValue : exactValue = child -> exactValue ; break ; default : elog ( ERROR , " " ) ; break ; } } } child = node -> args . items [ start ] ; child -> type = type ; switch ( type ) { case eAny : case eEmptyArray : break ; case eIs : child -> isType = isType ; break ; case eInequality : child -> bounds . leftBound = leftBound ; child -> bounds . rightBound = rightBound ; child -> bounds . leftInclusive = leftInclusive ; child -> bounds . rightInclusive = rightInclusive ; break ; case eExactValue : child -> exactValue = exactValue ; break ; default : elog ( ERROR , " " ) ; break ; } for ( i = start + 1 ; i < end ; i ++ ) node -> args . items [ i ] = NULL ; }
Process group of nodes representing conditions for the same field.
Process group of nodes representing conditions for the same field .