Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag support for sql #31

Closed
m0sth8 opened this issue Jul 4, 2016 · 2 comments
Closed

Add tag support for sql #31

m0sth8 opened this issue Jul 4, 2016 · 2 comments
Assignees
Labels
Milestone

Comments

@m0sth8
Copy link

m0sth8 commented Jul 4, 2016

Usually, it's very useful to mark queries with some tags.

This code db.Tag("disable_user:%s", userId).Update(user) might produce the next query UPDATE /* disable_user:10 */ ...

@AlekSi AlekSi added the feature label Jul 4, 2016
@AlekSi AlekSi added this to the v1.2 milestone Jul 4, 2016
@AlekSi AlekSi self-assigned this Jul 4, 2016
@AlekSi
Copy link
Member

AlekSi commented Jul 4, 2016

Do you have any examples in existing ORMs?

@AlekSi AlekSi removed this from the v1.2.0 milestone Aug 10, 2016
@AlekSi AlekSi added the triage label Aug 10, 2016
@AlekSi AlekSi removed their assignment Aug 24, 2016
@AlekSi
Copy link
Member

AlekSi commented Dec 20, 2016

@m0sth8 shared some details privately. The idea is to generate SQL statements with embedded comments, so it is possible to track them from RDMS logs back to application code. Sounds like a useful feature.

How RDMS support comments:

  • PostgreSQL supports /* */ sytax without problems. Optimizer hints are not supported.
  • MySQL supports /* */ syntax. It has hacks for MySQL specific code (/*! STRAIGHT_JOIN */) with optional version check (/*!50110 KEY_BLOCK_SIZE=1024 */) and optimizer hints (/*+ BKA(t1) */) after keywords SELECT, UPDATE, etc. Internets say that comments in statements can kill query cache: 1, 2, 3.
  • SQLite3 supports /* */ syntax. Not sure about how it affects cache, but it should not be a concern for SQLite3 user.
  • Microsoft SQL Server supports /* */ syntax. Comments can kill query cache: 1, 2.
  • Oracle supports /* */ syntax with hacks for optimizer hints (/*+ ALL_ROWS */) after keywords SELECT, UPDATE, etc.

How it should be implemented is an open question. Querier looks like a natural place, but then statements like BEGIN from DB will not be logged.

@AlekSi AlekSi added help-wanted and removed triage labels Dec 20, 2016
@AlekSi AlekSi added this to the v1.3.0 milestone Dec 21, 2016
@AlekSi AlekSi self-assigned this Dec 31, 2016
AlekSi added a commit that referenced this issue Jan 5, 2017
@AlekSi AlekSi closed this as completed Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants