Visualizzazione dei risultati da 1 a 5 su 5

Discussione: In o where con or

  1. #1

    In o where con or

    Ciao,
    Mi sarei aspettato che la seconda fosse + veloce prima
    codice:
    SELECT `np_petition`.`id`, count(np_sign.id) AS `total_sign` 
    FROM `np_petition` 
    INNER JOIN `np_sign` ON np_petition.id = np_sign.petition_id 
    WHERE (np_petition.STATUS = 'approved' OR np_petition.STATUS = 'confirmed' OR np_petition.STATUS = 'stopped') 
    GROUP BY `np_petition`.`id` 
    ORDER BY `np_petition`.`registration_datetime` DESC
     
    SELECT `np_petition`.`id`, count(np_sign.id) AS `total_sign` 
    FROM `np_petition` 
    INNER JOIN `np_sign` ON np_petition.id = np_sign.petition_id 
    WHERE np_petition.STATUS IN ('approved' ,'confirmed' , 'stopped') 
    GROUP BY `np_petition`.`id` 
    ORDER BY `np_petition`.`registration_datetime` DESC
    invece
    la prima restituisce i risultati in 8.3 secs
    la seconda in 11.5

    A livello di prestazioni IN non dovrebbe essere + performante di
    un where con diversi OR ?
    o sbaglio



    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2

    Re: In o where con or

    Originariamente inviato da whisher
    Ciao,
    Mi sarei aspettato che la seconda fosse + veloce prima

    invece
    la prima restituisce i risultati in 8.3 secs
    la seconda in 11.5

    A livello di prestazioni IN non dovrebbe essere + performante di
    un where con diversi OR ?
    o sbaglio
    La ricerca di IN() e' eseguita in binario. Quindi la conversione del tipo stringa in binary impiega un tot a seconda di cosa deve tradurre ....

    Prova a fare la stessa prova con costanti o numeri. Tieni anche presente che IN() oltre a 0 e 1 potrebbe anche ritornare NULL.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Grazie tante

    faccio delle prove (+ per info personale dato che lo schema è gia fatto)


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #4

    Re: Re: In o where con or

    Originariamente inviato da piero.mac
    Tieni anche presente che IN() oltre a 0 e 1 potrebbe anche ritornare NULL.
    non sapevo di questa cosa del NULL: quando potrebbe ritornare?

  5. #5

    Re: Re: Re: In o where con or

    Originariamente inviato da optime
    non sapevo di questa cosa del NULL: quando potrebbe ritornare?
    http://dev.mysql.com/doc/refman/5.0/...ml#function_in

    To comply with the SQL standard, IN returns NULL not only if the expression on the left hand side is NULL, but also if no match is found in the list and one of the expressions in the list is NULL.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.