Skip to content

FEATURE REQUEST: SQL comments #95

Description

@apatrida

It is important to be able to place comments in SQL, sometimes used for:

  • hints to the database
  • settings
  • documenting running queries for tracking by DBA's
  • tracing

Comments before/after SQL are very common, but sometimes even within.

Some SQL elements need comments before/after and some of this might be satisfied by FREE BLOCKS.

examples from MySQL:

-- optimizer to use the Block Nested Loop
SELECT /*+ BNL(t1, t2) */ * FROM t1 JOIN t2 ON t1.id = t2.t1_id;

-- version specific
CREATE TABLE t1 (a INT, KEY (a)) /*!50701 USING BTREE */;

-- marking queries so others know what is running, easy to see in Dolphie or PMM
/* adhoc - Fred */ SELECT * FROM megatable;

-- after, some people do it after
SELECT * FROM megatable; /* adhoc - Fred */

-- tracing
/* traceid-1234 */ SELECT ...
SELECT ... /* traceid=1234 */

-- from the docs:
SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY, f2_idx) */ f1
  FROM t3 WHERE f1 > 30 AND f1 < 33;
SELECT /*+ BKA(t1) NO_BKA(t2) */ * FROM t1 INNER JOIN t2 WHERE ...;
SELECT /*+ NO_ICP(t1, t2) */ * FROM t1 INNER JOIN t2 WHERE ...;
SELECT /*+ SEMIJOIN(FIRSTMATCH, LOOSESCAN) */ * FROM t1 ...;
EXPLAIN SELECT /*+ NO_ICP(t1) */ * FROM t1 WHERE ...;
SELECT /*+ MERGE(dt) */ * FROM (SELECT * FROM t1) AS dt;
INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2);

this might be similar to solving other inserts pre/post other aspects of a query, for example FORCE INDEX or USE INDEX type hints which are not in comments.

SELECT column1, column2
FROM table_name FORCE INDEX (index_name_1, index_name_2, ...)
WHERE condition;

if it is possible with free blocks at any position, then we can always write our own extensions that help with our particular databases.

So this could split out into multiple issues depending on what is supported natively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions