[development] The new menu system

Larry Garfield larry at garfieldtech.com
Fri Sep 29 02:55:02 UTC 2006


On Thursday 28 September 2006 10:56, Dries Buytaert wrote:
> On 28 Sep 2006, at 14:37, Earl Miles wrote:
> > The actual URL entered is: node/12/edit/foo
> >
> > the simplistic version of the query would be:
> >
> > SELECT * FROM menu WHERE path IN ('node/12/edit/foo', 'node/12/
> > edit', 'node/12/%/foo', 'node/%/edit/foo', 'node/%/%/foo', 'node/%/
> > edit', 'node/%') ORDER BY weight DESC;
> >
> > This does have an order of N complexity in that there are 2^N-1 URL
> > possibilities for every URL fragment you have -- which gets
> > unwieldy around 7, but it is rare that you get URLs that long,
> > though I imagine it does happen from time to time. At this time we
> > believe this is an acceptable cost compared to the cost of the
> > system it is replacing, while leaving us with maximum flexibility.
>
> Interesting aproach, Earl.  I think this might work, and relatively
> fast too. :-)

Indeed!  This qualifies as an "Ooo" in my book.  And even if it is a 2^n 
algorithm, it's still being done in SQL as a not-unusual SQL query.  It's 
absolutely guaranteed that MySQL or Postgres will be faster than any 
searching we do in PHP.  

I also agree with Kahlid that we should use something other than % for 
simplicity.  *, ?, #, there's plenty of other characters we can use that 
wouldn't make the SQL uglier.

-- 
Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson


More information about the development mailing list