jmueller17 / Aixada

Aixada helps self-managed consumption cooperatives to organize their flow of products, money, and information.
Other
33 stars 37 forks source link

Error al validar comanda: "generated error 1104:The SELECT would examine more than MAX_JOIN_SIZE rows......status "parsererror" occurred during loading data:Error: Invalid XML: Warning: Header may not contain more than a single header, new line detected in ... /php/ctrl/Orders.php on line 163" #307

Closed VictorJavaSpring closed 11 months ago

VictorJavaSpring commented 12 months ago

Hola!, ens ha donat error a l'hora de validar les comandes: error_Agost_2023-2gitr ... error_Agost_2023 ... l'error sembla que és a una query, (encara que sembla que també es queixa de que sobra un "header"). L'error surt en un POP UP i després es queda bloquejat .. error_loading el Pop up mostra el següent texte:

An error "Error: Invalid XML: 
Warning: Header may not contain more than a single header, 
new line detected in 
/customers/2/d/4/girasoldesantmarti.net/httpd.www/aixada/php/ctrl/Orders.php on line 163

        SELECT id, name, unit,
            max(r.uf_price) uf_price,
            max(r.rev_tax_percent) rev_tax_percent,
            max(r.iva_percent) iva_percent,
            round( max(r.uf_price) / 
                (1 + max(r.rev_tax_percent)/100) /
                (1 + max(r.iva_percent)/100), 2 ) gross_price,
            round( max(r.uf_price) / 
                (1 + max(r.rev_tax_percent)/100), 2 ) net_price
        FROM(
        select distinct
            p.id, p.name,
            if(p.orderable_type_id=3, 
                '(comentarios pedido)',
                um.unit) unit,
            ifnull(ots.unit_price_stamp, oi.unit_price_stamp) uf_price,
            ifnull(ots.rev_tax_percent, rev.rev_tax_percent) rev_tax_percent,
            ifnull(ots.iva_percent, iva.percent) iva_percent            
        from
            aixada_order_item oi
        left join 
            aixada_order_to_shop ots
        on  oi.id = ots.order_item_id
        join (
            aixada_product p,
            aixada_rev_tax_type rev, 
            aixada_iva_type iva,
            aixada_unit_measure um
        ) on 
            oi.product_id = p.id
            and rev.id = p.rev_tax_type_id
            and iva.id = p.iva_percent_id
            and um.id =  p.unit_measure_order_id where oi.order_id = 1556) r
        group by id, name, unit
        order by name; 
        generated error 1104: 
        The SELECT would examine more than MAX_JOIN_SIZE rows; 
        check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# 
        if the SELECT is okay", 
        status "parsererror" occurred during loading data: 
Warning:Header may not contain more than a single header, new line detected in 
/customers/2/d/4/girasoldesantmarti.net/httpd.www/aixada/php/ctrl/Orders.php 
on line 163

        SELECT id, name, unit,
            max(r.uf_price) uf_price,
            max(r.rev_tax_percent) rev_tax_percent,
            max(r.iva_percent) iva_percent,
            round( max(r.uf_price) / 
                (1 + max(r.rev_tax_percent)/100) /
                (1 + max(r.iva_percent)/100), 2 ) gross_price,
            round( max(r.uf_price) / 
                (1 + max(r.rev_tax_percent)/100), 2 ) net_price
        FROM(
        select distinct
            p.id, p.name,
            if(p.orderable_type_id=3, 
                '(comentarios pedido)',
                um.unit) unit,
            ifnull(ots.unit_price_stamp, oi.unit_price_stamp) uf_price,
            ifnull(ots.rev_tax_percent, rev.rev_tax_percent) rev_tax_percent,
            ifnull(ots.iva_percent, iva.percent) iva_percent            
        from
            aixada_order_item oi
        left join 
            aixada_order_to_shop ots
        on  oi.id = ots.order_item_id
        join (
            aixada_product p,
            aixada_rev_tax_type rev, 
            aixada_iva_type iva,
            aixada_unit_measure um
        ) on 
            oi.product_id = p.id
            and rev.id = p.rev_tax_type_id
            and iva.id = p.iva_percent_id
            and um.id =  p.unit_measure_order_id where oi.order_id = 1556) r
        group by id, name, unit
        order by name; 
generated error 1104: 
The SELECT would examine more than MAX_JOIN_SIZE rows;
check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay

He estat mirant i crec que on falla és al case 'getOrdersListing' de l'arxiu /php/control/Orders.php a:

    switch (get_param('oper')) {

        //returns a list of all orders summarized by provider within a given date range
        case 'getOrdersListing':
            echo get_orders_in_range(get_param('filter'), get_param('uf_id',0), get_param('fromDate',0), get_param('toDate',0), 
                get_param('steps',0), get_param('range',0));
            exit; 

La URL que monta és : http://www.girasoldesantmarti.net/aixada/manage_orders.php?filter=ordersForToday&lastPage=torn.php

Adjunto imatges, si teniu alguna idea, ens farieu un favor perqué no podem validar!

VictorJavaSpring commented 12 months ago

Nota: Lo dels headers crec que es refereix a les línies finals del Orders.php :

catch(Exception $e) {
    header('HTTP/1.0 401 ' . $e->getMessage());
    die ($e->getMessage());
}  

potser el $e->getMessage() és un missatge massa llarg..

VictorJavaSpring commented 12 months ago

He trobat aquesta info: _This error can occur if the MySQL query optimizer determines that the number of examined rows is going to exceed MAX_JOIN_SIZE. Setting the MySQL System Variable SQL_BIG_SELECTS=1 may resolve this error since doing so will cause the value for MAX_JOINSIZE to be ignored. i també aquests links, on donen diverses opcions: https://stackoverflow.com/questions/950465/mysql-sql-big-selects https://stackoverflow.com/questions/22630238/error-set-sql-big-selects-1-or-set-max-join-size

jorix commented 11 months ago

Ja veig...

Crec que es podria millorar l'eficiència d'aquesta SELECT afegint una clau primaria a aixada_order_to_shop:

ALTER TABLE aixada_order_to_shop add primary key (order_item_id);

PETICIÓ:
1.- Asegura't que SQL_BIG_SELECTS=0 2.- Prova si falla abans de fer el canvi. 3.- Afegeix la clau primaria a aixada_order_to_shop. 4.- Prova si funciona un cop fet el canvi. 5.- Informa dels resultats a aquest mateix issue.

ATENCIÓ:
Abans hauries de mirar que aquesta sentencia:

select count(*) from (
  SELECT order_item_id, count(*) FROM aixada_order_to_shop os group by order_item_id having count(*) > 1
) g;

retorna un 0!!


@jmueller17 : Què opines? Si et sembla faria un PR amb un canvi de BD que s'actibaria només si el select count(*) retorna 0.
Tot això un cop @VictorJavaSpring confirmés que no apareixen problemes en el dia a dia.

jorix commented 11 months ago

Nota: Lo dels headers crec que es refereix a les línies finals del Orders.php...

No té importancia, es normal que apareigui quan Aixada informa d'un error.

VictorJavaSpring commented 11 months ago

select count() from ( SELECT order_item_id, count() FROM aixada_order_to_shop os group by order_item_id having count(*) > 1 ) g; retorna 34 !

ALTER TABLE aixada_order_to_shop add primary key (order_item_id) retorna un #1062 - Duplicate entry '386685' for key 'PRIMARY' SELECT * FROM aixada_order_to_shop WHERE ORDER_ITEM_ID = 386685; retorna 1 registre només..

jorix commented 11 months ago

... retorna 34 !

Bé doncs fes:

ALTER TABLE aixada_order_to_shop add index (order_item_id);

Amb això la BD de dades ja tindrà un index per optimitzar la SELECT, i suposo que ja no es produirà l'error The SELECT would examine more than MAX_JOIN_SIZE rows;


Però...
m'intriga com es creen aquests duplicats.
Sense poder bussejar a la BD m'hes dificil d'imaginar...

VictorJavaSpring commented 11 months ago

Provant el canvi...

VictorJavaSpring commented 11 months ago

Els canvis han desbloquejat l'error de moment, gràcies.