Improved query canonicalization

The query does not need to be parsed for it to be canonicalized and the parsing
uses the PCRE2 library. The regular expressions were changed so that only one
call to the function which replaces literal unquoted values is made.
This commit is contained in:
Markus Makela
2016-01-06 15:17:28 +02:00
parent b01e8b2eec
commit 995ed8c9d2
5 changed files with 87 additions and 109 deletions

View File

@ -60,24 +60,26 @@ int main(int argc, char** argv)
while (!feof(infile))
{
fgets(readbuff,4092,infile);
char* nl = strchr(readbuff, '\n');
if(nl)
{
*nl = '\0';
}
psize = strlen(readbuff);
if (psize < 4092)
{
qbuff = gwbuf_alloc(psize + 7);
*(qbuff->sbuf->data + 0) = (unsigned char)psize;
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03;
memcpy(qbuff->start + 5,readbuff,psize + 1);
tok = qc_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok);
free(tok);
gwbuf_free(qbuff);
}
qbuff = gwbuf_alloc(psize + 7);
*(qbuff->sbuf->data + 0) = (unsigned char)psize;
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03;
memcpy(qbuff->start + 5,readbuff,psize + 1);
tok = qc_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok);
free(tok);
gwbuf_free(qbuff);
}
fclose(infile);
fclose(outfile);
mysql_library_end();
return 0;
return 0;
}

View File

@ -9,7 +9,7 @@ select * from tst where fname like '?';
select * from tst where lname like '?' order by fname;
insert into tst values ("?","?"),("?",?),("?","?");
drop table if exists tst;
create table tst(fname varchar(30), lname varchar(30));
create table tst(fname varchar(?), lname varchar(?));
update tst set lname="?" where fname like '?' or lname like '?';
delete from tst where lname like '?' and fname like '?';
select ? from tst where fname='?' or lname like '?';