I'm doing two types of consultations. When I reference a field, the query is done in 4 seconds but when I do not place reference it tends to take 30 seconds.
This is the one that takes 30 seconds:
if(cliente == "" && termPago=="0" && moneda=="0" && estado=="0")
{ query = "SELECT f.idFactura, e.nombreEmpleado, f.fecha,
c.nombreCliente, c.nomenclaturaCliente, t.nombreTipo AS 'estado',
t1.nombreTipo AS 'terminoPago', t2.nombreTipo AS 'tipoFactura',
f.comentario, f.total, t3.nombreTipo AS 'moneda' FROM
encabezadofactura f INNER JOIN cliente c ON f.clienteID = c.idCliente
INNER JOIN tipos t on f.estadoFactura = t.idTipos INNER JOIN tipos t1
on f.terminosPago = t1.idTipos INNER JOIN tipos t2 on f.tipoFactura =
t2.idTipos INNER JOIN tipos t3 on f.moneda = t3.idTipos INNER JOIN
empleado e ON f.empleadoID = e.idEmpleado WHERE f.fecha BETWEEN
'"+desde+"' AND '"+hasta+"' ORDER BY f.idFactura ASC"; }
This is done in 3 seconds:
> else if(estado != "0" && termPago == "0" && moneda == "0" && client == "")
> { query = "SELECT f.idFactura, e.nombreEmpleado, f.fecha,
> c.nombreCliente, c.nomenclaturaCliente, t.nombreTipo AS 'estado',
> t1.nombreTipo AS 'terminoPago', t2.nombreTipo AS 'tipoFactura', f.comentario, f.total, t3.nombreTipo AS 'moneda' FROM
> encabezadofactura f INNER JOIN cliente c ON f.clienteID = c.idCliente
> INNER JOIN tipos t on f.estadoFactura = t.idTipos INNER JOIN tipos t1
> on f.terminosPago = t1.idTipos INNER JOIN tipos t2 on f.tipoFactura =
> t2.idTipos INNER JOIN tipos t3 on f.moneda = t3.idTipos INNER JOIN
> empleado e ON f.empleadoID = e.idEmpleado WHERE f.fecha BETWEEN
> '"+desde+"' AND '"+hasta+"' AND f.estadoFactura="+estado+" ORDER BY
> f.idFactura ASC";
> }
I have the correct relationships, the problem is generated when I do not place a reference or when I only put the client's name.