node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

nodejs v18.17.1 / v20.9.0 - pg ^8.11.0 - slow select query

Open Dimitris-Tzilopoylos opened this issue 2 years ago • 7 comments

I am using the following query to retrieve users from database, and before this one i just perform a count(*) to retrieve the total number of users.

SELECT coalesce(json_agg(_0_users),'[]') as users 
        FROM (
          SELECT row_to_json((
            SELECT _0_users
            FROM ( SELECT _0_users.id,_0_users.email,_0_users.password,_0_users.name,_0_users.last_name,_0_users.created_at,_0_users.verified,_0_users.blacklist,_0_users.profile_image,_0_users.role_id,_0_users.country_id,_0_users.city,_0_users.phone,_0_users.address,_0_users.postal_code,_0_users.is_business,_0_users.business_name,_0_users.business_address,_0_users.business_country_id,_0_users.vat,_0_users.parent_id) _0_users )) _0_users
            FROM (
              SELECT  _0_users.id,_0_users.email,_0_users.password,_0_users.name,_0_users.last_name,_0_users.created_at,_0_users.verified,_0_users.blacklist,_0_users.profile_image,_0_users.role_id,_0_users.country_id,_0_users.city,_0_users.phone,_0_users.address,_0_users.postal_code,_0_users.is_business,_0_users.business_name,_0_users.business_address,_0_users.business_country_id,_0_users.vat,_0_users.parent_id FROM public.users _0_users
       ) _0_users
       ) _0_users

The execution with nodejs v18.17.1 / v20.9.0 - pg ^8.11.0 results to something between 60 and 92 ms for both count and the query mentioned above, but the same process with nodejs v16.20.2 results to 12ms for both queries (average). Are there any issues with node-postgres and nodejs versions > 16? Am I missing something?

Dimitris-Tzilopoylos avatar Nov 12 '23 18:11 Dimitris-Tzilopoylos

Cannot reproduce it on different machines,except windows 11 for unknown reasons

Dimitris-Tzilopoylos avatar Nov 12 '23 22:11 Dimitris-Tzilopoylos

Very strange! Sounds like more of an issue w/ something internal to node on v18/20 on windows. Please lmk if you track down what it is!

brianc avatar Nov 13 '23 15:11 brianc