iTranslated by AI
Missed the April Fool's deadline, but I wrote a patch to add the PLEASE clause to SQLite3
Introduction
Around April 1st, it seems like adding a PLEASE clause to MySQL was trending.
And it appears other RDBMS followed suit, creating a festival of adding PLEASE clauses.
First, PostgreSQL:
And Oracle:
I completely missed the boat. It was a major blunder.
I only noticed it yesterday, April 4th.
I just had to join in
It's already 12:00 AM on April 5th, but I wrote a patch to add a PLEASE clause to SQLite3.
diff --git a/src/parse.y b/src/parse.y
index b748e1917..782199fb7 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -151,6 +151,12 @@ ecmd ::= explain cmdx SEMI. {NEVER-REDUCE}
explain ::= EXPLAIN. { pParse->explain = 1; }
explain ::= EXPLAIN QUERY PLAN. { pParse->explain = 2; }
%endif SQLITE_OMIT_EXPLAIN
+cmdlist ::= cmdlist pcmd.
+cmdlist ::= pcmd.
+%ifndef SQLITE_OMIT_PLEASE
+pcmd ::= please cmdx SEMI. {NEVER-REDUCE}
+please ::= PLEASE. { pParse->please = 1; }
+%endif SQLITE_OMIT_PLEASE
cmdx ::= cmd. { sqlite3FinishCoding(pParse); }
///////////////////// Begin and end transactions. ////////////////////////////
@@ -224,7 +230,7 @@ columnname(A) ::= nm(A) typetoken(Y). {sqlite3AddColumn(pParse,&A,&Y);}
// at the beginning.
//
%token ABORT ACTION AFTER ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST.
-%token CONFLICT DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL.
+%token CONFLICT DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL PLEASE.
%token OR AND NOT IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
%token GT LE LT GE ESCAPE.
@@ -237,7 +243,7 @@ columnname(A) ::= nm(A) typetoken(Y). {sqlite3AddColumn(pParse,&A,&Y);}
CONFLICT DATABASE DEFERRED DESC DETACH DO
EACH END EXCLUSIVE EXPLAIN FAIL FOR
IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN
- QUERY KEY OF OFFSET PRAGMA RAISE RECURSIVE RELEASE REPLACE RESTRICT ROW ROWS
+ QUERY KEY OF OFFSET PLEASE PRAGMA RAISE RECURSIVE RELEASE REPLACE RESTRICT ROW ROWS
ROLLBACK SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITH WITHOUT
NULLS FIRST LAST
%ifdef SQLITE_OMIT_COMPOUND_SELECT
diff --git a/src/select.c b/src/select.c
index 7c84bd7d6..1a1898222 100644
--- a/src/select.c
+++ b/src/select.c
@@ -6119,6 +6119,9 @@ int sqlite3Select(
}
#endif
+ if (pParse->please == 0) {
+ sqlite3OsSleep(db->pVfs, 1000*1000);
+ }
assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 783950fb0..6931cb66b 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -3485,6 +3485,7 @@ struct Parse {
ynVar nVar; /* Number of '?' variables seen in the SQL so far */
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
u8 explain; /* True if the EXPLAIN flag is found on the query */
+ u8 please; /* True if the PLEASE flag is found on the query */
u8 eParseMode; /* PARSE_MODE_XXX constant */
#ifndef SQLITE_OMIT_VIRTUALTABLE
int nVtabLock; /* Number of virtual tables to lock */
diff --git a/tool/mkkeywordhash.c b/tool/mkkeywordhash.c
index bbb0ccf29..1909f01a0 100644
--- a/tool/mkkeywordhash.c
+++ b/tool/mkkeywordhash.c
@@ -164,6 +164,11 @@ struct Keyword {
#else
# define RETURNING 0x00400000
#endif
+#ifdef SQLITE_OMIT_PLEASE
+# define PLEASE 0
+#else
+# define PLEASE 0x00800000
+#endif
/*
@@ -273,6 +278,7 @@ static Keyword aKeywordTable[] = {
{ "OVER", "TK_OVER", WINDOWFUNC, 3 },
{ "PARTITION", "TK_PARTITION", WINDOWFUNC, 3 },
{ "PLAN", "TK_PLAN", EXPLAIN, 0 },
+ { "PLEASE", "TK_PLEASE", PLEASE, 1 },
{ "PRAGMA", "TK_PRAGMA", PRAGMA, 0 },
{ "PRECEDING", "TK_PRECEDING", WINDOWFUNC, 3 },
{ "PRIMARY", "TK_PRIMARY", ALWAYS, 1 },
I had written extensions for SQLite3 before, but this was my first time reading the source code of the SQLite3 core parser, so it took quite a bit of time. However, I managed to finish it as a proper patch that supports things like configure flags, rather than just a quick-and-dirty hack.
Actually trying it out
The SQLite3 shell has a .timer on command, so I'll run it with that enabled. First, the case without PLEASE.
It gets delayed by 1 second due to its "chuunibyou" (edgy) phase. Now, executing it with PLEASE.
Its mood has improved, and normal performance is restored.
Conclusion
It's already April 5th, but I'm glad SQLite3 could join the party late. That's a relief. I hope you all have fun with your own "demon-modding" of SQLite3!
Discussion