On Nov 3, 8:11 am, JP <[email protected]> wrote: > Hi guys, > > I am working on a problem, that I would like to see if anyone might be > able to help me with. > > I have a simple rails application that uses a controller to find a > record in a database. I grab the path that the client is trying to > access, and then I look in a database to see if I have a record that > matches this path and return an appropriate response. > > The table looks like this (simplified example): > > | path | response | > ------------------------------ > | /users | { users } | > > This is all well and nice, and works the way it should, to expose an > extremely simple REST service. What I would like to do now is to be > able to insert a regular expression, that I will then use to match > against the path. That way having a record value like /\/users\/(\d*)/ > to match a client request path like /users/1234. > > | path | response | > ------------------------------ > | /\/users\/(\d*)/ | { users } | > > I first looked > athttp://www.postgresql.org/docs/8.3/static/functions-matching.html > (section 9.7.2), but that is the reverse problem, where the input is a > regular expression. > > Does my problem make sense, and is it even possible?
The challenge here is that there's no DB (that I'm aware of) that can meaningfully index regexes, meaning that every query against the table is going to be a full table scan. How bad that is depends on how big your table is: - if it's just a couple dozen records, it won't be too slow. You may want to just load all the objects and scan them on the Ruby side, as the implementation will be much more straightforward and performance won't be an issue. - if it's tens of thousands of records, you're probably screwed. DB- side lookups will still be slow, and loading everything into memory will also be slow. The MySQL manual mentions that you can use a DB column for the pattern in a REGEXP expression, so that might be looking into. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

