volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

[feature request] MySQL Optimizer Hints #1320

Open mickeyreiss opened 10 months ago

mickeyreiss commented 10 months ago

MySQL has support for Optimizer Hints, which implemented with comments that appear between SELECT and the column list.

For example:

SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM users;

I would like to be able to insert optimizer hints with a query mod, maybe something like this:

models.Users(
    qm.OptimizerHint("MAX_EXECUTION_TIME(%d)", 1000),
).All(ctx)
mickeyreiss commented 10 months ago

Here is some WIP for adding this feature: https://github.com/volatiletech/sqlboiler/commit/14739a8b57f82b13b3327690760fafbccee18636. It looks like it would be relatively simple to add—similar to https://github.com/volatiletech/sqlboiler/pull/872.

stephenafamo commented 10 months ago

Can you create a PR for this? It would be much easier to review.

mickeyreiss commented 10 months ago

Can you create a PR for this? It would be much easier to review.

@stephenafamo my solution isn't fully baked yet. For example, I haven't considered databases other than MySQL. I wanted to get feedback on the feature and approach before opening a pull request. If you see any issues as is, feel free to leave a comment on the commit.

stephenafamo commented 8 months ago

I haven't considered databases other than MySQL

Yes, this is an issue because SQLboiler uses the same query builder for all dialects.

Personally, I think it is fine. Because it is similar to qm.Returning which is not supported in MySQL but we have mods for it.