My first post: path_set_alias() and multiple aliases
Hi, path_set_alias($path, $alias) inserts a new alias in case there is already an alias for $path. However drupal_lookup_path() keeps picking up the old alias. It makes sense to keep the old alias so links don't break in a website, but why look up the old alias when generating a URL? Is this a bug? Shouldn't the query "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC" in drupal_lookup_path() be rewritten as "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC" Also, shouldn't this be db_result(db_query_range()) instead of just db_result(db_query())? Nir
As an API, I think it should return all aliases of a path or should take an additional parameter like 'all','latest','oldest' depending on how you want it. But yeah it returns the oldest alias and just one entry. Dipen Chaudhary http://www.dipenchaudhary.com http://playdrupal.com On Thu, Feb 19, 2009 at 3:49 AM, Nir Aides <nir@winpdb.org> wrote:
Hi,
path_set_alias($path, $alias) inserts a new alias in case there is already an alias for $path. However drupal_lookup_path() keeps picking up the old alias. It makes sense to keep the old alias so links don't break in a website, but why look up the old alias when generating a URL?
Is this a bug?
Shouldn't the query "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC" in drupal_lookup_path() be rewritten as "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC"
Also, shouldn't this be db_result(db_query_range()) instead of just db_result(db_query())?
Nir
On 19-Feb-09, at 3:59 AM, Dipen wrote:
As an API, I think it should return all aliases of a path or should take an additional parameter like 'all','latest','oldest' depending on how you want it. But yeah it returns the oldest alias and just one entry.
I seem to remember that unless you do an ORDER BY that the order of returned results are implementation dependent. I can't seem to find anything to back that up other than a few old notes though. So while MySQL returns the first matched result in order of insertion, I think that could change when using some other RDBMS. Anyone have any more info? --Andrew
You just can't trust ordering without using order by. The behaviour is undefined. Indexes can affect the order you get stuff back in aswell as insertion order as you will effectively select positions from the index if you are lucky enough to hit it. Stew On 2/19/09, Andrew Berry <andrewberry@sentex.net> wrote:
On 19-Feb-09, at 3:59 AM, Dipen wrote:
As an API, I think it should return all aliases of a path or should take an additional parameter like 'all','latest','oldest' depending on how you want it. But yeah it returns the oldest alias and just one entry.
I seem to remember that unless you do an ORDER BY that the order of returned results are implementation dependent. I can't seem to find anything to back that up other than a few old notes though. So while MySQL returns the first matched result in order of insertion, I think that could change when using some other RDBMS.
Anyone have any more info?
--Andrew
-- Sent from my mobile device
My 2c If I remember correctly from my DB classes, all tables in a relational databases are unordered, you cannot assume an order. My experience is that all databases use table (or insertion) order for simple select statements (like select x from y), but you might get "strange" ordering while using grouping / having clauses. So the safest is to specify the order, you never know if mysql is going to behave differently. Peter -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Andrew Berry Sent: donderdag 19 februari 2009 15:37 To: development@drupal.org Subject: Re: [development] My first post: path_set_alias() and multiple aliases On 19-Feb-09, at 3:59 AM, Dipen wrote:
As an API, I think it should return all aliases of a path or should take an additional parameter like 'all','latest','oldest' depending on how you want it. But yeah it returns the oldest alias and just one entry.
I seem to remember that unless you do an ORDER BY that the order of returned results are implementation dependent. I can't seem to find anything to back that up other than a few old notes though. So while MySQL returns the first matched result in order of insertion, I think that could change when using some other RDBMS. Anyone have any more info? --Andrew
Short answer: Yep don't count on the order of anything that doesn't have an order by clause. Longer answer just cause some seem interested: Most DB's (mysql included) will return unordered expressions in the order that they are retrieved, which sometimes equates to order of insertion but not always. All kinds of things can change that. Indexes get use because of data in the where clause. Maintenance activities in some databases will change the order of storage. Some databases will reuse of deleted rows causing the order to be different. Some databases store multiple tables data in the same file (oracle) and this can really get crazy when space gets reused. The biggest real world example of this is that in one of my larger databases, the order of things changed when we exported and re- imported data (to facilitate a character set conversion), which exposed a whole bunch of queries where the unfiltered list seemed to be broken. These were just queries that didn't have order by clauses in the expression. But I've seen query plans change in upgrades of database software also. So while it may seem to work, even across databases, you really shouldn't count on it, not even within a database architecture. Dave On Feb 20, 2009, at 10:41 AM, Peter Droogmans wrote:
My 2c
If I remember correctly from my DB classes, all tables in a relational databases are unordered, you cannot assume an order. My experience is that all databases use table (or insertion) order for simple select statements (like select x from y), but you might get "strange" ordering while using grouping / having clauses. So the safest is to specify the order, you never know if mysql is going to behave differently.
Peter
-----Original Message----- From: development-bounces@drupal.org [mailto:development- bounces@drupal.org] On Behalf Of Andrew Berry Sent: donderdag 19 februari 2009 15:37 To: development@drupal.org Subject: Re: [development] My first post: path_set_alias() and multiple aliases
On 19-Feb-09, at 3:59 AM, Dipen wrote:
As an API, I think it should return all aliases of a path or should take an additional parameter like 'all','latest','oldest' depending on how you want it. But yeah it returns the oldest alias and just one entry.
I seem to remember that unless you do an ORDER BY that the order of returned results are implementation dependent. I can't seem to find anything to back that up other than a few old notes though. So while MySQL returns the first matched result in order of insertion, I think that could change when using some other RDBMS.
Anyone have any more info?
--Andrew
Quoting Nir Aides <nir@winpdb.org>:
Hi,
path_set_alias($path, $alias) inserts a new alias in case there is already an alias for $path. However drupal_lookup_path() keeps picking up the old alias. It makes sense to keep the old alias so links don't break in a website, but why look up the old alias when generating a URL?
Is this a bug?
You should review the issue queue. I know that there are issues related to path_set_alias.
Shouldn't the query "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC" in drupal_lookup_path() be rewritten as "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC"
Also, shouldn't this be db_result(db_query_range()) instead of just db_result(db_query())?
I don't find this query in drupal_lookup_path for D6 or D7. The query should have a LIMIT 1 at least since db_result is only returning the first row. -- Earnie http://r-feed.com Make a Drupal difference and review core patches. -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
On Wed, Feb 18, 2009 at 11:19 PM, Nir Aides <nir@winpdb.org> wrote:
Hi,
path_set_alias($path, $alias) inserts a new alias in case there is already an alias for $path. However drupal_lookup_path() keeps picking up the old alias. It makes sense to keep the old alias so links don't break in a website, but why look up the old alias when generating a URL?
Please see http://drupal.org/node/358315 Damien
participants (8)
-
Andrew Berry -
Damien Tournoud -
David Metzler -
Dipen -
Earnie Boyd -
Nir Aides -
Peter Droogmans -
Stewart Robinson