I am making a web application using AJAX, it sent a data to another page that processes it to make a query to a DB, generally 100 records are returned and the approximate time from when the request is sent to the response is one minute, I know I waited a long time, what can I do to speed up the response more since they ask me not to take too long?
AJAX request
$(document).ready(function () {
$("#btnEnviar").click(function() {
var datos ={fechaTae : $("#fechaTae").val()};
$.ajax({
type: "POST",
url: "buscaTae.asp",
data: datos,
success: function(resultado) {
document.getElementById("muestraTae").innerHTML = resultado;
}
});
});
});
SQL query
SELECT a.id, a.tramite, a.movimiento, a.monto, a.fecha, a.cliente as cliente,
a.nombre, a.operativa, a.poliza, a.pedido, a.rechazo, a.observaciones,
a.usercreate,a.datecreate,a.userupdate, a.dateupdate, a.comentario, a.tipo,
a.presencial, a.Inactivo, a.useroracle, a.emergente, a.vip, b.id AS id2,
b.id_sol, b.tipo as tipoo, b.numero as numero, b.monto AS monto, b.aplicar,
b.datecreate,c.folio as telcel,c.datecreate as envio
FROM Sol_deposito_v2 a, Solicitud_lineas b,folios_tae_v2 c
WHERE a.id = b.id_sol and ((LEN(numero)='10' and substring(numero,1,3)
<> '722') or (LEN(numero)<='5' and a.operativa <> '142')) and
b.id=c.id_solicitud and convert(varchar,c.datecreate,103)='"&fecha&"'
order by c.datecreate
At first you should fix the sql query a bit, the int should be compared with int, otherwise sql does an internal conversion for each operation to be able to compare, and it takes time. On the other hand, I prefer to use Joins to make the code more readable. Finally, so that Sql does not waste time evaluating the order of the joins, we will add OPTION(FORCE ORDER). Surely this will speed up the times.