Hi,

I see that the current query executes two sub-selects, can't this be improved with a query like the one I propose in #434308: Filter duplicate translations? It uses the neat tecnique of ORDER BY CASE which I find very appropriate for the purpose.

Thanks for the module btw, I hope to see an improved and stable version released soon.

Regards,
Antonio.

CommentFileSizeAuthor
#6 select-translation-improve-query_v1.patch2.4 KBao2

Comments

Alice Heaton’s picture

Looks nice, I did not know of this syntax.

Does it work with both MySql and PostGre ?

ao2’s picture

Hi,

I tested it with MySql only, but I read on the web that it should work with PostGre too.
Anyway it would be better to test that :)

In the proposed query the original translation case is not handled but it shouldn't be too difficult to add it.

Regards,
Antonio

Alice Heaton’s picture

Thanks, this is very usefull. My queries are very ugly, so this will be very good :)

There's another couple of patches I need to look at for this module ; I'll try and find time to do this this week and I'll make a beta release.

ao2’s picture

Hi Anselm,

if you haven't looked at this yet I could try to do it myself and send a patch.

Regards,
Antonio

Alice Heaton’s picture

ao2 : I haven't had time to do it - a patch would be great thanks !!!

ao2’s picture

Category: support » task
Status: Active » Needs work
StatusFileSize
new2.4 KB

Ok,

if I understood the drupal scheme right and the original version comes always first we could handle the original language case implicitly in the ELSE part of the CASE, something like this (in MySQL):

set @current_language='it';
set @default_language='en';

set @curr_lang_priority = 1;
set @def_lang_priority = 2;
set @orig_lang_priority = 3;

SELECT nid,tnid, language, title
  FROM node AS n1
  WHERE (n1.promote <> 0) AND (n1.status <> 0) AND (
    tnid IS NULL OR tnid=0 OR nid=(
      SELECT nid FROM node AS n2
        WHERE n2.tnid=n1.tnid
        ORDER BY
          CASE n2.language
            WHEN @current_language THEN @curr_lang_priority
            WHEN @default_language THEN @def_lang_priority
            ELSE @orig_lang_priority
          END
        LIMIT 1
    )
  )
  ORDER BY n1.sticky DESC, n1.created DESC;

Patch attached which implements this idea in Select Translation.

Needs work and testing :)

Regards,
Antonio

ao2’s picture

The patch exposes this bug #369629: db_rewrite_sql breaks on sql having "order by" clause so it is not fully usable for now.

ao2’s picture

Title: Improve query. » Improve query
Version: 6.x-0.x-dev » 8.x-1.x-dev
Issue summary: View changes
Status: Needs work » Postponed

The current version of select_translation uses uncorrelated subqueries, but using the CASE syntax could still be prettier if it's comparable in terms of performance.

For now I am postponing this issue, but if someone has a test case with a lot of nodes please get in touch.

Thanks,
Antonio

ao2’s picture

anybody’s picture

Version: 8.x-1.x-dev » 2.x-dev

Switching to the latest branch.

anybody’s picture

Status: Postponed » Closed (outdated)

No real activity since 2009. Closing outdated.