Bug #37002 DESCRIBE returns error 1064
Submitted: 27 May 2008 11:27 Modified: 31 May 2008 19:15
Reporter: Eugen Schülter Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.51b-community-nt OS:Any
Assigned to: CPU Architecture:Any
Tags: DESC, subselect, VIEW

[27 May 2008 11:27] Eugen Schülter
Description:
I use a subselect in a view to retrieve a long pattern (varchar) to be used in REGEXP.
The problem is, that somehow this view get corrupted and is not listed anymore in INFORMATION_SCHEMA.VIEWS(?)

Any statement (I tried out) referencing the view returns:
mysql> describe vPrimNRTI;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'equal
(_latin1'Prim NRTI', '') limit 1)))' at line 1
mysql> select * from vPrimNRTI where patID=1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'equal
(_latin1'Prim NRTI', '') limit 1)))' at line 1
mysql> show create view vPrimNRTI;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'equal
(_latin1'Prim NRTI', '') limit 1)))' at line 1

This also occured on debian linux with 5.0.51-3-log (Debian).

The views I use are created all together from a source file.

a) When I recreated the view in question (cut and paste to mysql client), the error disapeared.
b) When I looked at the table INFORMATION_SCHEMA.VIEWS directly, selecting the TABLE_NAME, the views with the error where not listed anymore AND desc now returns:
mysql> desc vPrimNNRTI;
ERROR 1109 (42S02): Unknown table 'vprimnnrti' in information_schema

First I thougt the problem had something to do with the subselect because once I got a error message like "subselect returns more than one row" which is not possible by the declaration of the tables involved. That's the reason I added the LIMIT 1 clause.

Here are the tables and views:
CREATE TABLE sSearchPatterns (
  name             VARCHAR (20)    NOT NULL PRIMARY KEY,    #name of regexp
  type             CHAR (1)        NOT NULL DEFAULT 'R',    #R=regexp S=normal select condition
  description      VARCHAR (80)    NOT NULL DEFAULT '',     #
  pattern          VARCHAR (400)   NOT NULL
) Engine=InnoDB COMMENT='Regular expression patterns used to select records';

INSERT INTO sSearchPatterns
   (name, description, pattern)
VALUES
   (
   'Prim NRTI', 'Select primary resistance NRTI associated (transmitted) mutations',
   '((^| )41[A-Z]*L)|((^| )65[A-Z]*R)|((^| )67[A-Z]*(G|N))|((^| )70[A-Z]*R)|((^| )74[A-Z]*V)|((^| )75[A-Z]*(A|M|T|S))|((^| )77[A-Z]*L)|((^| )115[A-Z]*F)|((^| )116[A-Z]*Y)|((^| )151[A-Z]*M)|((^| )184[A-Z]*(I|V))|((^| )210[A-Z]*W)|((^| )215[A-Z]*(Y|F|C|D|E|S|I|V))|((^| )219[A-Z]*(E|R|Q))'
   ),
   (
   'Prim NNRTI', 'Select primary resistance NNRTI associated (transmitted) mutations',
   '((^| )100[A-Z]*I)|((^| )101[A-Z]*E)|((^| )103[A-Z]*(N|S))|((^| )106[A-Z]*(A|M))|((^| )181[A-Z]*(I|C))|((^| )188[A-Z]*(C|L|H))|((^| )190[A-Z]*(A|S|E|Q))|((^| )225[A-Z]*H)|((^| )230[A-Z]*L)|((^| )263[A-Z]*L)'
   ),
   (
   'Prim PI', 'Select primary resistance PI associated (transmitted) mutations',
   '((^| )24[A-Z]*I)|((^| )30[A-Z]*N)|((^| )32[A-Z]*I)|((^| )46[A-Z]*I)|((^| )47[A-Z]*(A|V))|((^| )48[A-Z]*V)|((^| )50[A-Z]*(V|L))|((^| )53[A-Z]*L)|((^| )54[A-Z]*(V|L|M|A|T|S))|((^| )73[A-Z]*(C|S|T|A))|((^| )82[A-Z]*(A|F|T|S|M))|((^| )84[A-Z]*(V|A|C))|((^| )88[A-Z]*(D|S))|((^| )90[A-Z]*M)'
   ),
   (
   'Prim Revert', 'Select primary resistance revertant mutations',
   '((^| )215[A-Z]*(A|C|D|E|L|N|S))'
   ),
   (
   'HIV-DB NRTI', 'Select NRTI mutations acc. Stanfords HIV-DB',
   '((^| )41[A-Z]*L)|((^| )62[A-Z]*V)|((^| )65[A-Z]*R)|((^| )67[A-Z]*N)|((^| )70[A-Z]*(E|R))|((^| )74[A-Z]*(I|V))|((^| )75[A-Z]*(I|M|T))|((^| )77[A-Z]*(I|L))|((^| )115[A-Z]*F)|((^| )116[A-Z]*Y)|((^| )151[A-Z]*M)|((^| )184[A-Z]*(I|V))|((^| )210[A-Z]*W)|((^| )215[A-Z]*(F|Y))|((^| )219[A-Z]*(E|Q))'
   )
;

#select isolates with sequences having primary NRTI mutations
CREATE OR REPLACE VIEW vPrimNRTI AS SELECT
   i.patID, i.isolate, r.seqID, subst mut
FROM
   tIsolates i INNER JOIN tRawSequences r ON (i.isolate=r.isolate)
   INNER JOIN tdSeqMutations m ON (r.seqID=m.seqID)
WHERE
   (m.contains='RT') AND
   (subst REGEXP (SELECT pattern FROM sSearchPatterns WHERE name='Prim NRTI' LIMIT 1))
;

#select isolates with sequences having primary NNRTI mutations
CREATE OR REPLACE VIEW vPrimNNRTI AS SELECT
   i.patID, i.isolate, r.seqID, subst mut
FROM
   tIsolates i INNER JOIN tRawSequences r ON (i.isolate=r.isolate)
   INNER JOIN tdSeqMutations m ON (r.seqID=m.seqID)
WHERE
   (m.contains='RT') AND
   (subst REGEXP (SELECT pattern FROM sSearchPatterns WHERE name='Prim NNRTI' LIMIT 1))
;

#select isolates with sequences having primary PI mutations
CREATE OR REPLACE VIEW vPrimPI AS SELECT
   i.patID, i.isolate, subst mut
FROM
   tIsolates i INNER JOIN tRawSequences r ON (i.isolate=r.isolate)
   INNER JOIN tdSeqMutations m ON (r.seqID=m.seqID)
WHERE
   (m.contains='PRO') AND
   (subst REGEXP (SELECT pattern FROM sSearchPatterns WHERE name='Prim PI' LIMIT 1))
;

Although I'll write a better alternative using a stored procedure, I have a bad feeling about this.

How to repeat:
I'm not sure.
When I resubmitted the whole source file with the views, the error was gone.

I stopped the server, deleted all InnoDB files and own DBs, recreated all from the sql sources (the create views source beeing the last one) and the error was there again.

Then I inserted some sample data (including data for sSearchPatterns), resubmitted the create views script again and the error was gone.

I repeated the whole procedure, now inserting only data into sSearchPatterns before creating the views, all other tables are still empty => the error is gone!
Then I truncated the table sSearchPatterns and the error still is gone :-)
[28 May 2008 13:27] MySQL Verification Team
Thank you for the bug report. I could not test because missed tables when creating the views. Could you please provide them?. Thanks in advance.
[29 May 2008 10:45] Eugen Schülter
OK, here is a complete sample:

#============
CREATE DATABASE eg;
USE eg;

CREATE TABLE sTest (
  pat      VARCHAR (20)    NOT NULL PRIMARY KEY,
  subst    VARCHAR (200)   NOT NULL DEFAULT ''
) Engine=InnoDB COMMENT='Test BUG 37002';

INSERT INTO sTEST VALUES('test','10I, 67N');

CREATE TABLE sSearchPatterns (
  name        VARCHAR (20)    NOT NULL PRIMARY KEY,    #name of regexp
  type        CHAR (1)        NOT NULL DEFAULT 'R',    #R=regexp S=normal
  description VARCHAR (80)    NOT NULL DEFAULT '',     #
  pattern     VARCHAR (400)   NOT NULL
) Engine=InnoDB COMMENT='Regular expression patterns used to select records';

/*
Run without this insert statement and desc vPrimNRTI gives ERROR 1064 !
(You can also truncate sSearchPatterns before the create view with the same result)

Running with the insert before creating the view and everything is fine ( I hope ;-) )
*/

INSERT INTO sSearchPatterns
   (name, description, pattern)
VALUES
   (
   'Prim NRTI', 'Select primary resistance NRTI associated (transmitted) mutations',
   '((^| )41[A-Z]*L)|((^| )65[A-Z]*R)|((^| )67[A-Z]*(G|N))|((^| )70[A-Z]*R)|((^| )74[A-Z]*V)|((^| )75[A-Z]*(A|M|T|S))|((^| )77[A-Z]*L)|((^| )115[A-Z]*F)|((^| )116[A-Z]*Y)|((^| )151[A-Z]*M)|((^| )184[A-Z]*(I|V))|((^| )210[A-Z]*W)|((^| )215[A-Z]*(Y|F|C|D|E|S|I|V))|((^| )219[A-Z]*(E|R|Q))'
   );

CREATE OR REPLACE VIEW vPrimNRTI AS SELECT
   a.pat, a.subst mut
FROM
   sTest a
WHERE
   (a.pat='test') AND
   (a.subst REGEXP (SELECT pattern FROM sSearchPatterns WHERE name='Prim NRTI'))
;

#============

Hope this helps.
[31 May 2008 19:15] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior since version 5.0.60, although bug is repatable with older versions. Please upgrade to Enterprise server or wait next Community release.