question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Draft][API Design] Query hints, options.

See original GitHub issue

Opened 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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
igor-tkachevcommented, Nov 3, 2020

We can add three generic methods to support different types of hints

var query =
(
   from t1 in table1.TableHint("...")
   join t2 in table2.JoinHint("...") on t1.Id equals t2.Id
   select new { t1, t2 }
)
.QueryHint("...")

Also, we can add specific API for each provider.

1reaction
jogibear9988commented, Nov 9, 2020

I think it would be usefull if we can specify that a Hint should only be used for a specific provider.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RESTful API design: list value options for query param
This method allows a client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without ...
Read more >
REST API Design: Filtering, Sorting, and Pagination
Advanced REST API design guidelines for API filtering, sorting, and pagination.
Read more >
Best practices for REST API design
Here's a small example where an API can accept a query string with various query parameters to let us filter out items by...
Read more >
APIs & Query String Parameters
Prior to using query string parameters, always reference the API's documentation. Not every API is designed the same and not every query ......
Read more >
Web API design best practices - Azure Architecture Center
Learn the best practices for designing web APIs that support platform ... and this guide focuses on designing REST APIs for HTTP.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found