mirror of
https://github.com/SuiteCRM/SuiteCRM.git
synced 2026-03-02 19:16:58 -05:00
Performance problem due to id being implicitly converted #5108
Labels
No labels
Area: API
Area: Campaigns
Area: Cases
Area: Clean Up
Area: Clean Up: Performance
Area: Dashlets
Area: Databases
Area: Developer Tools
Area: Elasticsearch
Area: Elasticsearch
Area: Emails
Area: Emails:Campaigns
Area: Emails:Cases
Area: Emails:Compose
Area: Emails:Config
Area: Emails:Templates
Area: Environment
Area: Installation
Area: Language
Area: Mobile
Area: Module
Area: PDFs
Area: PHP8
Area: Reports
Area: Studio
Area: Styling
Area: Upgrading
Area: Workflow
Area:Activity Stream
Area:Calls
Area:Import
Area:Projects
Area:Search
Area:Surveys
Area:Themes
Area:Users
Branch:Hotfix
Good First Issue
Hacktoberfest
Help Wanted
PR:Community Contribution
PR:Type:Enhancement
Priority:Critical
Priority:Important
Priority:Moderate
Severity: Major
Severity: Minor
Severity: Moderate
Status: Requires Code Review
Status: Requires Updates
Status: Stale
Status: Team Investigating
Status:Assessed
Status:Fix Proposed
Status:Needs Assessed
Status:Requires Automated Tests
Type: Bug
Type:Deprecated
Type:Discussion
Type:Duplicate
Type:Invalid
Type:Question
Type:Suggestion
Type:Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/SuiteCRM-SuiteCRM#5108
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @imens-frankd on GitHub (Oct 2, 2023).
Select statements which retrieve a records based on the id have bad performance on mssql.
This is due tot the fact that the generated sql statement pass the id as a nvarchar
'''
SELECT id ,accounts.name as parent_name , accounts.assigned_user_id owner FROM accounts WHERE deleted=0 AND id=N'14110000-568c-0050-4dbd-08db66e86890'
'''
but the id column in the database is varchar.
Because of this mssql uses a index scan instead of an index seek for the id.
This is much slower and uses up a lot of IO on the sql server.
Expected Behavior
The generated sql statement should use varchar as type for the id value it passes.
'''
SELECT id ,accounts.name as parent_name , accounts.assigned_user_id owner FROM accounts WHERE deleted=0 AND id='14110000-568c-0050-4dbd-08db66e86890'
'''
Actual Behavior
The generated sql statement uses nvarchar as type for the id value it passes.
'''
SELECT id ,accounts.name as parent_name , accounts.assigned_user_id owner FROM accounts WHERE deleted=0 AND id=N'14110000-568c-0050-4dbd-08db66e86890'
'''
Context
This results in overloading of our sql server.
This should be high priority
@johnM2401 commented on GitHub (Oct 11, 2023):
Hey!
Thanks for getting in touch!
I've had a test of this on my local environment, (PHP8.2, Suite 7.14.1, Ubuntu 18.04, mariadb 10.4.12)
However, it does not appear to be generating as nvarchar on my system, i'm afraid.
An Example query is:
Would you be able to provide some information on your environment?
Such as:
Or any specific steps to replicate?
(ie: Changing field types in Studio, Specific Queries [if any] )
Thanks!
@imens-frankd commented on GitHub (Oct 12, 2023):
Hi John,
we are using V7.11.12
The code adds the character N in front of all single quoted parts in the SQL. This tells mssql that the value in the SQL statement is off type nvarchar. See :
github.com/salesagility/SuiteCRM@c43eaa311f/include/database/MssqlManager.php (L1893)The columns in our database however are sometimes varchar.
@ebogaard commented on GitHub (Oct 12, 2023):
The difference results reported here are due to @imens-frankd reporting this issue with Microsoft SQL Server, and @johnM2401 is using MariaDB (=MySQL type server).
This issue is only with SQL Server, not MySQL-type DB servers.