Problem Note 66707: An incorrect query might be sent to a database when two like-named variables are being selected and grouped on, resulting in slow performance
A performance issue might occur when you query a database management system (DBMS) table via a LIBNAME engine and the following conditions exist in your SQL procedure query:
- You are selecting two like-named variables where the shorter of the two named variables is listed first.
- You are assigning a label to both variables.
- You are summarizing a third variable.
- The two like-named variables appear on the GROUP BY clause.
- The second variable is not being renamed.
- The two like-named variables are both from the same table listed on the FROM clause.
The following code illustrates one case that might produce slow performance:
proc sql;
create table results as
select x label='the 1st variable', x1 label='the 2nd variable', count(y) as cnt
from dblib.test
group by x,x1;
quit;
The slow performance is caused by an incorrect query being passed to the database where the first variable is listed twice in the GROUP BY clause rather than the two different variables appearing in the GROUP BY clause. This behavior results in a database error because most databases require that variables that appear in a SELECT clause must also appear in the GROUP BY clause when the query includes a summary function. Because of the error, SAS® software might attempt to pass a second query in which it removes the summarization. Instead of the DBMS performing the processing, SAS reads in the DBMS table and the summarization in performed by SAS. This behavior often results in slower performance due to the extra data being read into SAS.
To work around the issue, remove the label modifiers from the query and add them in a subsequent step.
Click the Hot Fix tab in this note to access the hot fix for this issue.
Operating System and Release Information
SAS System | Base SAS | Solaris for x64 | 9.4_M6 | | 9.4 TS1M6 | |
Linux for x64 | 9.4_M6 | | 9.4 TS1M6 | |
HP-UX IPF | 9.4_M6 | | 9.4 TS1M6 | |
64-bit Enabled Solaris | 9.4_M6 | | 9.4 TS1M6 | |
64-bit Enabled AIX | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Ultimate x64 | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Ultimate 32 bit | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Professional x64 | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Professional 32 bit | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Home Premium x64 | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Home Premium 32 bit | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Enterprise x64 | 9.4_M6 | | 9.4 TS1M6 | |
Windows 7 Enterprise 32 bit | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2019 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2016 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2012 Std | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2012 R2 Std | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2012 Datacenter | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2008 for x64 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2008 R2 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows Server 2008 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 10 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8.1 Pro x64 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8.1 Pro 32-bit | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8.1 Enterprise x64 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8 Pro x64 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8 Pro 32-bit | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8 Enterprise x64 | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft Windows 8 Enterprise 32-bit | 9.4_M6 | | 9.4 TS1M6 | |
Microsoft® Windows® for x64 | 9.4_M6 | | 9.4 TS1M6 | |
z/OS 64-bit | 9.4_M6 | | 9.4 TS1M6 | |
z/OS | 9.4_M6 | | 9.4 TS1M6 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Type: | Problem Note |
Priority: | high |
Date Modified: | 2020-10-01 17:02:42 |
Date Created: | 2020-09-29 17:01:01 |