[Draft][API Design] Query hints, options.
See original GitHub issueOpened this issue for discussion about API design. Feel free to correct spelling and comment missed parts. It is completely draft and can be changed frequently depending on found ambiguous scenarios.
Sample query
var query =
from t1 in table1
join t2 in table2 on t1.Id equals t2.Id
select new { t1, t2 }
Oracle
https://docs.oracle.com/cd/B13789_01/server.101/b10752/hintsref.htm#30459
namespace LinqToDB.DataProvider.Oracle;
Any query hint
query = query.StatementHint(q => $"LEADING({q.t1} {q.t2}) USE_NL({q.t1}) INDEX({q.t1} emp_emp_id_pk) USE_MERGE({q.t1}) FULL({q.t1})")
Flashback query
https://oracle-base.com/articles/10g/flashback-query-10g
var query =
from t1 in table1.AsOfScn(scnNumber)
join t2 in table2.AsOfTimestamp(timestamp) on t1.Id equals t2.Id
select new { t1, t2 }
AsOfScn/AsOfTimestamp
applied to query should apply AS OF
table hint to all tables in query. So the following queries are equivalent:
var query = query.AsOfScn(scnNumber)
var query =
from t1 in table1.AsOfScn(scnNumber)
join t2 in table2.AsOfScn(scnNumber) on t1.Id equals t2.Id
select new { t1, t2 }
PostgreSQL
Looks like for PostgresSQL we can only define locks after select statement:
https://www.postgresql.org/docs/current/sql-select.html
Consider to add AfterHint
which should add text exactly after whole query:
var query = query.AfterHint(q => $"FOR KEY UPDATE OF {q.t1}");
MySql
Looks like the same hints as for Oracle https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html#optimizer-hints-syntax
Informix
Looks like the same hints as for Oracle but divided by comma https://www.ibm.com/developerworks/data/zones/informix/library/techarticle/0502fan/0502fan.html
SqLite
Currently found only INDEXED BY injected before table name https://www.tutlane.com/tutorial/sqlite/sqlite-indexed-by
Consider to add IndexedBy
extension for ITable<>
var query =
from t1 in table1.IndexedBy("index_name")
join t2 in table2 on t1.Id equals t2.Id
select new { t1, t2 }
SqlServer
https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql?view=sql-server-ver15
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
We can add three generic methods to support different types of hints
Also, we can add specific API for each provider.
I think it would be usefull if we can specify that a Hint should only be used for a specific provider.