Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 56b9a54

Browse files
committed
Fix problem with | in ~ comparison using index.
1 parent a1d9186 commit 56b9a54

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
lines changed

src/backend/parser/gram.y

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.79 1999/05/20 12:12:55 wieck Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.80 1999/05/21 04:40:04 momjian Exp $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -5347,7 +5347,7 @@ mapTargetColumns(List *src, List *dst)
53475347
static Node *makeIndexable(char *opname, Node *lexpr, Node *rexpr)
53485348
{
53495349
Node *result = NULL;
5350-
5350+
53515351
/* we do this so indexes can be used */
53525352
if (strcmp(opname,"~") == 0 ||
53535353
strcmp(opname,"~*") == 0)
@@ -5360,47 +5360,64 @@ static Node *makeIndexable(char *opname, Node *lexpr, Node *rexpr)
53605360
char *match_least = palloc(strlen(n->val.val.str)+2);
53615361
char *match_most = palloc(strlen(n->val.val.str)+2);
53625362
int pos, match_pos=0;
5363+
bool found_pipe = false;
53635364

5364-
/* skip leading ^ */
53655365
for (pos = 1; n->val.val.str[pos]; pos++)
53665366
{
5367-
if (n->val.val.str[pos] == '.' ||
5368-
n->val.val.str[pos] == '?' ||
5369-
n->val.val.str[pos] == '*' ||
5370-
n->val.val.str[pos] == '[' ||
5371-
n->val.val.str[pos] == '$' ||
5372-
(strcmp(opname,"~*") == 0 && isalpha(n->val.val.str[pos])))
5373-
break;
5367+
if (n->val.val.str[pos] == '|')
5368+
{
5369+
found_pipe = true;
5370+
break;
5371+
}
53745372
if (n->val.val.str[pos] == '\\')
53755373
pos++;
5376-
match_least[match_pos] = n->val.val.str[pos];
5377-
match_most[match_pos++] = n->val.val.str[pos];
53785374
}
53795375

5380-
if (match_pos != 0)
5376+
/* skip leading ^ */
5377+
if (!found_pipe)
53815378
{
5382-
A_Const *least = makeNode(A_Const);
5383-
A_Const *most = makeNode(A_Const);
5384-
5385-
/* make strings to be used in index use */
5386-
match_least[match_pos] = '\0';
5387-
match_most[match_pos] = '\377';
5388-
match_most[match_pos+1] = '\0';
5389-
least->val.type = T_String;
5390-
least->val.val.str = match_least;
5391-
most->val.type = T_String;
5392-
most->val.val.str = match_most;
5379+
for (pos = 1; n->val.val.str[pos]; pos++)
5380+
{
5381+
if (n->val.val.str[pos] == '.' ||
5382+
n->val.val.str[pos] == '?' ||
5383+
n->val.val.str[pos] == '*' ||
5384+
n->val.val.str[pos] == '[' ||
5385+
n->val.val.str[pos] == '$' ||
5386+
(strcmp(opname,"~*") == 0 && isalpha(n->val.val.str[pos])))
5387+
break;
5388+
if (n->val.val.str[pos] == '\\')
5389+
pos++;
5390+
if (n->val.val.str[pos] == '\0')
5391+
break;
5392+
match_least[match_pos] = n->val.val.str[pos];
5393+
match_most[match_pos++] = n->val.val.str[pos];
5394+
}
5395+
5396+
if (match_pos != 0)
5397+
{
5398+
A_Const *least = makeNode(A_Const);
5399+
A_Const *most = makeNode(A_Const);
5400+
5401+
/* make strings to be used in index use */
5402+
match_least[match_pos] = '\0';
5403+
match_most[match_pos] = '\377';
5404+
match_most[match_pos+1] = '\0';
5405+
least->val.type = T_String;
5406+
least->val.val.str = match_least;
5407+
most->val.type = T_String;
5408+
most->val.val.str = match_most;
53935409
#ifdef USE_LOCALE
5394-
result = makeA_Expr(AND, NULL,
5395-
makeA_Expr(OP, "~", lexpr, rexpr),
5396-
makeA_Expr(OP, ">=", lexpr, (Node *)least));
5410+
result = makeA_Expr(AND, NULL,
5411+
makeA_Expr(OP, "~", lexpr, rexpr),
5412+
makeA_Expr(OP, ">=", lexpr, (Node *)least));
53975413
#else
5398-
result = makeA_Expr(AND, NULL,
5399-
makeA_Expr(OP, "~", lexpr, rexpr),
5400-
makeA_Expr(AND, NULL,
5401-
makeA_Expr(OP, ">=", lexpr, (Node *)least),
5402-
makeA_Expr(OP, "<=", lexpr, (Node *)most)));
5414+
result = makeA_Expr(AND, NULL,
5415+
makeA_Expr(OP, "~", lexpr, rexpr),
5416+
makeA_Expr(AND, NULL,
5417+
makeA_Expr(OP, ">=", lexpr, (Node *)least),
5418+
makeA_Expr(OP, "<=", lexpr, (Node *)most)));
54035419
#endif
5420+
}
54045421
}
54055422
}
54065423
}
@@ -5420,9 +5437,9 @@ static Node *makeIndexable(char *opname, Node *lexpr, Node *rexpr)
54205437
n->val.val.str[pos+1] != '%')
54215438
break;
54225439
if(n->val.val.str[pos] == '_')
5423-
break;
5424-
if (n->val.val.str[pos] == '\\' ||
5425-
n->val.val.str[pos] == '%')
5440+
break;
5441+
if (n->val.val.str[pos] == '\\' ||
5442+
n->val.val.str[pos+1] == '%')
54265443
pos++;
54275444
if (n->val.val.str[pos] == '\0')
54285445
break;

0 commit comments

Comments
 (0)