A Case to Optimize PSQL Query Performance with INNER JOIN SYCONTCT & SYCONREL Tables

A Case to Optimize PSQL Query Performance with INNER JOIN SYCONTCT & SYCONREL Tables

Release Date: 11/29/2023
Version: 7.x & Up

Q - With our custom web application, we attempt to find an existing customer and associated contact when creating new customers via the Elliott web services. We are finding the customer just fine, but when I attempt to retrieve the contacts with QueryTurnAround web services, we are getting a timeout error: Pervasive.Data.SqlClient.PsqlException (0x80004005): Pervasive.Data.SqlClient.Lna.k: [LNA][Pervasive][ODBC Engine Interface]S1T00Timeout expired.

QUERY

SYCONTCT_ID, SYCONTCT_EMAIL_ADDR, SYCONTCT_NAME, SYCONTCT_LNK_ADR_FLG, SYCONTCT_ADDR_1, SYCONTCT_ADDR_2, SYCONTCT_CITY, SYCONTCT_STATE, SYCONTCT_ZIP, SYCONTCT_COUNTRY, SYCONTCT_LNK_TEL_FLG, SYCONTCT_PHONE, SYCONTCT_PHONE_EXT, SYCONTCT_SRCH_NAME, SYCONTCT_HOME_PHONE, SYCONTCT_MOBIL_PHONE, SYCONTCT_BIRTH_YEAR, SYCONTCT_BIRTH_MON, SYCONTCT_BIRTH_DAY FROM SYCONTCT INNER JOIN SYCONREL ON SYCONTCT.SYCONTCT_ID = SYCONREL.SYCONREL_CONTACT_ID WHERE SYCONREL_DETAIL_FILE='ARCUSFIL' AND SYCONREL_REF_ID='476806'

Since this is QueryTurnAround, you can just add "SELECT" to the above query to test it in the PSQL Control Center.  Can you advise how to get around the time out issue?

A - First, I logged in to your server and I saw that your database engine is PSQL 11. Upgrading to the latest PSQL 15 may help. 

Second, I tried your query myself and it does take a little bit of time (like 18”), but not to the point of timeout. I think it may take more time if the corresponding SYCONTCT and SYCONREL tables are not cached in the database memory. This could happen if the server was rebooted.

I spent a little bit of time optimizing your query as follows, which you can try:

SYCONTCT_ID, SYCONTCT_EMAIL_ADDR, SYCONTCT_NAME, SYCONTCT_LNK_ADR_FLG, SYCONTCT_ADDR_1, SYCONTCT_ADDR_2, SYCONTCT_CITY, SYCONTCT_STATE, SYCONTCT_ZIP, SYCONTCT_COUNTRY, SYCONTCT_LNK_TEL_FLG, SYCONTCT_PHONE, SYCONTCT_PHONE_EXT, SYCONTCT_SRCH_NAME, SYCONTCT_HOME_PHONE, SYCONTCT_MOBIL_PHONE, SYCONTCT_BIRTH_YEAR, SYCONTCT_BIRTH_MON, SYCONTCT_BIRTH_DAY FROM SYCONTCT WHERE SYCONTCT_ID = (SELECT SYCONREL_CONTACT_ID FROM SYCONREL WHERE SYCONREL_DETAIL_FILE='ARCUSFIL' AND SYCONREL_REF_ID='476806')

It took about 2-3" to execute. It is faster, but still not as fast as I would like it to be. I like to see the result return in sub second.  You could try breaking up the query into two steps by first executing this query:

SYCONREL_CONTACT_ID FROM SYCONREL WHERE SYCONREL_DETAIL_FILE='ARCUSFIL' AND SYCONREL_REF_ID='476806'

Then use the returned Contact ID to construct the next query:

SYCONTCT_ID, SYCONTCT_EMAIL_ADDR, SYCONTCT_NAME, SYCONTCT_LNK_ADR_FLG, SYCONTCT_ADDR_1, SYCONTCT_ADDR_2, SYCONTCT_CITY, SYCONTCT_STATE, SYCONTCT_ZIP, SYCONTCT_COUNTRY, SYCONTCT_LNK_TEL_FLG, SYCONTCT_PHONE, SYCONTCT_PHONE_EXT, SYCONTCT_SRCH_NAME, SYCONTCT_HOME_PHONE, SYCONTCT_MOBIL_PHONE, SYCONTCT_BIRTH_YEAR, SYCONTCT_BIRTH_MON, SYCONTCT_BIRTH_DAY FROM SYCONTCT WHERE SYCONTCT_ID = %ReturnedContactID%

Both queries were executed instantly and hence they will still be faster when combining them together. I cannot give good explanation on why the query is slower with your INNER JOIN case. It is possible PSQL is having problems optimizing the INNER JOIN in this case.  Therefore, the alternative is that we can take this matter into our own hands to help PSQL optimize the performance. Generally speaking, we can assume PSQL will perform well with a query from a single table with the WHERE condition utilizing the index columns.


EMK

    • Related Articles

    • A Case to Diagnose Elliott SOAP Web Services Errors with Log Files

      'Release Date: 08/15/2024 Modified Date: 08/23/2024 Version: 8.5 & Up When a web developer calls Elliott SOAP web services, he/she should place a try catch block so if there is an error with the web services call, the error can be caught at the ...
    • QueryTurnaround

      QueryTurnaround.asmx This web service lets the user execute the SQL query. ExecuteQuery Usage: ExecuteQueryResult = A.ExecuteQuery(UserName, UserPassword, query, numberOfRecords) Parameters UserName and UserPassword are not used at this moment. Input ...
    • Configure PSQL Server Memory Usage

      Version: Any Release Date: 12/17/2021 Q - Can you tell us why PSQL process is taking up so much memory? Is there anything we can do? See sample screen below: A - PSQL server by default can take up about 60ish% of the server memory. This is ...
    • Slow PSQL Relational Engine Performance

      Release Date: 12/15/2017 Many users encounter situations where a particular relational engine SQL query can sometimes be slow. This can be complicated to diagnose due to a lot of reasons. Sometimes it's because of a SQL SELECT statement that's not ...
    • Avalara Setup Procedures - Updating Elliott Tables

      ' Release Date: 4/28/23 Version: 8.6 and Above Updating Elliott Tables Generate States Table If you do not have state table setup yet, go to Accounts Receivable-> Maintenance-> State File -> Generate The system comes with a pre-defined table of all ...