squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

Support for STRAIGHT_JOIN in Mysql and MariaDB

Open questin opened this issue 5 years ago • 1 comments

Fantastic work to all involved! I recently came across a need that was difficult to work around. We had queries taking much longer than expected after a DB version change. In the end, it was discovered that the query optimizer had been changed in the updated DB. I needed to be able to get the original code performing well again which was using Squirrel to build the select statements.

Would you consider supporting the STRAIGHT_JOIN join option in Mysql and MariaDB. It would allow the ability to specify join order where the optimizer gets it wrong. Addition seems simple enough:

Add to select.go:

// Join adds a STRAIGHT_JOIN clause to the query. func (b SelectBuilder) StraightJoin(join string, rest ...interface{}) SelectBuilder { return b.JoinClause("STRAIGHT_JOIN "+join, rest...) }

Would be very helpful.

Thanks!

questin avatar Jun 11 '20 21:06 questin

To avoid an explosion of complexity I've generally avoided dialect-specific syntax. You've already discovered the JoinClause method - this is exactly what its for.

lann avatar Jun 11 '20 22:06 lann