rails / arel

A Relational Algebra
2.06k stars 390 forks source link

Use constants in to sql #388

Closed BenMorganIO closed 8 years ago

BenMorganIO commented 9 years ago

I was going through the comments at the top and discovered that strings were a major hotsport for creating SQL. Therefore, I decided to continue looking through the source and realized... wait... there's still spots to optimize. I froze the constants to give it an ever so minor perf boost (fingers crossed) and made sure that some of the existing constants were used.

Also added a new one for ' AS ', 'UNBOUNDED', and ' ESCAPED ' and would love to add more; this way we could also have a laundry list of text that we use :D

Parenthesis are also widely used and they can also be moved to the constants. The only problem is that some of the require a space before/after and some of the shouldn't. I'm think this should also get tacked on to this PR:

OPEN_PAREN    = '('.freeze
OPEN_PAREN_S  = '( '.freeze
CLOSE_PAREN   = ')'.freeze
CLOSE_PAREN_S = ') '.freeze
rafaelfranca commented 8 years ago

With Ruby 2.3 this kind of optimization is not required anymore so I prefer to not merge. Thank you so much for the pull request.