Slow running query through node
See original GitHub issueThere is one particular query that takes 25seconds to run through node-mssql whereas if i run it directly on SSMS it takes 200ms
Expected behaviour:
Would expect the run time to be comparable
Running the queries and monitoring on SQL server profiler:
node/mssql
SSMS
Actual behaviour:
Not sure why but the query consistently takes 25seconds through node/mssql
Configuration:
Connection Configuration
const config = {
user: DB_USER,
password: DB_PASS,
server: DB_HOST,
requestTimeout: 300000,
pool: {
min: 5
}
}
How I connect to run the query:
const dbc = new sql.connect(config);
const ClientDb = 'Client.dbo';
const StockDb = 'Stock.dbo';
export {
dbc,
sql,
ClientDb,
StockDb
}
import { dbc, sql, StockDb } from '../../config/db'
Then the actual query:
return dbc.then(pool => {
return pool.request()
.input('clientId', sql.Int, clientId)
.input('startDate', sql.DateTime, new Date(startDate))
.input('endDate', sql.DateTime, new Date(endDate))
.query(`SELECT v.Id as VehicleId,
n.Name as Make,
m.Name as Model,
v.Variant as Variant,
v.Registration as Registration,
v.Price As Price,
v.OfferPrice as OfferPrice,
v.OfferDisplay as OfferDisplay,
d.Name as DealershipName,
v.StockDate as StockDate,
v.PurchaseStandIn as SIV,
s.Name as PurchaseSource,
DATEDIFF(day, StockDate, GETDATE()) as DaysInStock,
v.SoldDate as SoldDate,
v.SoldPrice as SoldPrice,
s1.Name as SoldSource
FROM ${StockDb}.UsedVehicles v
JOIN ${StockDb}.Models m on m.Id = v.ModelId
JOIN ${StockDb}.Makes n ON n.Id = m.MakeId
JOIN ${StockDb}.Dealerships d on d.Id = v.DealershipId
LEFT JOIN ${StockDb}.UsedPriceSources s on s.Id = v.PurchasePriceSourceId
LEFT JOIN ${StockDb}.UsedPriceSources s1 on s1.Id = v.SoldPriceSourceId
WHERE v.Status = 3
AND v.ClientId = @clientId
AND v.SoldDate between @startDate AND @endDate
ORDER BY SoldDate ASC`)
}).then(result => {
return result.recordset;
}).catch(err => {
console.error(err);
});
Software versions
- NodeJS: 10
- node-mssql: 6.2
- SQL Server: 2017
Issue Analytics
- State:
- Created 3 years ago
- Comments:13
Top Results From Across the Web
Streaming query with mssql and node, very slow the first time
If I try to stream data from a query, using the node-mssql example , the first time I execute its very slow. It...
Read more >Query running slow in one node - Oracle Communities
Hi, Execute your query on node where query is running very slow. Get SID and execute query above to see what is event...
Read more >Factors affecting query performance - Amazon Redshift
More nodes means more processors and more slices, which enables your queries to process faster by running portions of the query concurrently across...
Read more >[Node] Slow queries for PostgreSQL on NodeJS agent
I recently started using the NodeJS APM agent in my API, and would like to capture information about SQL queries that are executed....
Read more >Identifying the Top Slow Queries - Couchbase Developer Portal
The duration of the query from when it started executing to when it completed. node, IP address and port of the query engine...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Happy it’s not a node-mssql/tedious issue as when running directly in SSMS with
StockDb.dbo.
in front of the table names it does take 25seconds tooInteresting that the issue doesn’t occur with msnodesqlv8
The only difference i can see is with Tedious/node-mssql it runs as RPC and with msnodesqlv8 it runs as SQLBatch
I’m actually running into the same issue as OP where things are running slow. Below is timings of events happening in my AWS Lambda:
My database is a standard SQL database running with Azure. I don’t have any of these speed problems at all using Azure Data Studio. The query that was timed above takes 58 milliseconds with the data studio.
The query is an extremely basic “select” statement that is only querying 15 records with 5 columns.