Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL...
Transcript of Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL...
![Page 1: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/1.jpg)
Misty Johnson Wisconsin Department of Health Services,
Madison, WI
JUST PASSING THROUGH…OR ARE YOU?
DETERMINE WHEN SQL PASS‐THROUGH OCCURS TO OPTIMIZE
YOUR QUERIES
![Page 2: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/2.jpg)
Outline• SAS/ACCESS• SQL Pass‐Through Facility• LIBNAME Interface Engine
• Triggers of Implicit SQL Pass‐Through• Helpful system options
• Query Comparisons • Effect of Processing Location on Run time• Summary
![Page 3: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/3.jpg)
SAS/ACCESS
![Page 4: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/4.jpg)
SAS/ACCESS
DBMSBase SAS
SAS/ACCESS• Separate licensed product• Communicate with a Data Base Management System (DBMS)• Two components:
SQL Pass‐Through Facility
LIBNAME Interface Engine
![Page 5: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/5.jpg)
Component 1:
SQL PASS‐THROUGH FACILITY
![Page 6: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/6.jpg)
SQL Pass‐Through Facility• Send queries directly to DBMS
• Faster processing• PROC SQL coding structure
• SAS SQL• Native SQL
PROC SQL;CONNECT TO ODBC (DATASRC=FMS_PROD USER=&SYSUSERID. DBPROMPT=YES);
SELECT *FROM CONNECTION TO ODBC
/* THIS CODE PROCESSED ON DBMS */(SELECT DISTINCT Contract_Year AS year, Profile_ID AS profid, Appn AS app, Proj AS prj, Resp AS raFROM DBO.VOUCHER_CODINGWHERE CONTRACT_YEAR IN ('14','15','16','17'));/* END CODE PROCESSED ON DBMS */
DISCONNECT FROM ODBC;QUIT;
![Page 7: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/7.jpg)
SQL Pass‐Through Facility
Passes query directly to the DBMSCan use native SQL statements/functions
Larger code structureMust use PROC SQL
![Page 8: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/8.jpg)
Component 2:
LIBNAME INTERFACE ENGINE
![Page 9: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/9.jpg)
LIBNAME Interface Engine• Link to DBMS like a SAS Library
LIBNAME CARSSQ ODBC DATASRC=… SCHEMA=… USER=…;
![Page 10: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/10.jpg)
LIBNAME Interface Engine• Communicate with DBMS• Engine optimizes queries
• Specific to DBMS
• PROC SQL or DATA step coding structure• SAS only
LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;
PROC SQL;SELECT …FROM CARSSQ.VOUCHER_CODINGWHERE …;
QUIT;
![Page 11: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/11.jpg)
LIBNAME Interface Engine
Simple codingCan use PROC SQL or DATA step
Cannot use native SQLMust understand triggers of implicit SQL pass‐through
![Page 12: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/12.jpg)
SQL Pass‐Through Facility
•DBMS
Libname Engine Interface
•SAS •DBMS (implicit SQL pass‐through)
Where does Processing Occur?
![Page 13: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/13.jpg)
Best of both worlds??• Simple coding structure• Pass‐through to DBMS
• Triggers of implicit SQL pass‐through
Libname Engine Interface
•SAS •DBMS (implicit SQL pass‐through)
![Page 14: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/14.jpg)
WHAT TRIGGERS IMPLICIT SQL PASS‐THROUGH?
![Page 15: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/15.jpg)
Implicit SQL Pass‐Through Triggers
• DISTINCT• JOIN• UNION• COMPUTED• Aggregate functions (SUM, MAX, etc)
• WHERE clause
PROC SQL DATA step
![Page 16: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/16.jpg)
Conditions that Prohibit Pass‐Through• Multiple, disparate librefs• Most DATA set options• SAS functions in the SELECT clause• Use of DIRECT SQL= in LIBNAME option• Any generated SQL syntax not accepted by the DBMS
![Page 17: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/17.jpg)
Handy Options for Implicit Pass‐Through
• Displays SELECT clause generated by the libname engine
• Notification if implicit pass‐through occurred
• Displays all the SQL statements generated by the LIBNAME engine
• Notification if implicit pass‐through occurred
DEBUG=DBMS_SELECT SASTRACE=‘,,,d’
![Page 18: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/18.jpg)
QUERY PROCESSED ON SAS
![Page 19: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/19.jpg)
Query Processed on SAS (script)OPTIONS DEBUG=DBMS_SELECT SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;LIBNAME OLD 'L:\BFSPROC\CARSVOUCHERS';
LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;
PROC SQL;CREATE TABLE old.TABLE2 ASSELECT Contract_Year AS year, Profile_ID AS profid,
Appn AS app, Proj AS prj, Resp AS ra, Pcnt AS perctFROM CARSSQ.VOUCHER_CODING as CodetableWHERE CONTRACT_YEAR IN ('14','15','16','17');
QUIT;
![Page 20: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/20.jpg)
Query Processed on SAS (log)9 LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;NOTE: Libref CARSSQ was successfully assigned as follows:
Engine: ODBC
11 <PROC SQL statements here>ODBC: AUTOCOMMIT is NO for connection 0ODBC: AUTOCOMMIT turned ON for connection id 0DBMS_SELECT: SELECT * FROM "DBO"."VOUCHER_CODING"
ODBC_1: Prepared: on connection 0SELECT * FROM "DBO"."VOUCHER_CODING"
DBMS_SELECT: SELECT "Contract_Year", "Profile_ID", "Appn", "Proj", "Resp", "Pcnt FROM "DBO"."VOUCHER_CODING" WHERE (("Contract_Year" IN ('14','15','16','17')))
ODBC_2: Prepared: on connection 0SELECT "Contract_Year", "Profile_ID", "Appn", "Proj", "Resp", "Pcnt" FROM"DBO"."VOUCHER_CODING" WHERE (("Contract_Year" IN ('14','15','16','17')))
ODBC_3: Executed: on connection 0Prepared statement ODBC_2NOTE: Table OLD.TABLE2 created, with 2406 rows and 13 columns
17 QUIT;NOTE: PROCEDURE SQL used (Total process time):
real time 11.12 secondscpu time 0.18 seconds
SASTRACE DEBUG=DBMS_SELECT
![Page 21: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/21.jpg)
Trigger = DISTINCT
QUERY PROCESSED ON THE DBMS
![Page 22: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/22.jpg)
Query Processed on the DBMS (script)OPTIONS DEBUG=DBMS_SELECT SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;LIBNAME OLD 'L:\BFSPROC\CARSVOUCHERS';
LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;
PROC SQL;CREATE TABLE old.TABLE2 ASSELECT DISTINCT Contract_Year AS year, Profile_ID AS
profid, Appn AS app, Proj AS prj, Resp AS ra, Pcnt AS perctFROM CARSSQ.VOUCHER_CODING as CodetableWHERE CONTRACT_YEAR IN ('14','15','16','17');
QUIT;
![Page 23: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/23.jpg)
Query Processed on the DBMS (log)9 LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;NOTE: Libref CARSSQ was successfully assigned as follows:
Engine: ODBC
11 <PROC SQL statements here>ODBC: AUTOCOMMIT is NO for connection 0ODBC: AUTOCOMMIT turned ON for connection id 0DBMS_SELECT: SELECT * FROM "DBO"."VOUCHER_CODING"
ODBC_1: Prepared: on connection 0SELECT * FROM "DBO"."VOUCHER_CODING"
ODBC: AUTOCOMMIT is NO for connection 1ODBC: AUTOCOMMIT turned ON for connection id 1DBMS_SELECT: select distinct Codetable."year", Codetable."profid", Codetable."app",Codetable."prj", Codetable."ra", Codetable."perct" from "DBO"."VOUCHER_CODING" Codetable where (Codetable."Contract_Year" in ('14','15','16','17'))) Codetable
ODBC_2: Prepared: on connection 1select distinct Codetable."year", Codetable."profid", Codetable."app", Codetable."prj",
Codetable."ra", Codetable."perct" from ( select Codetable."Contract_Year" as "year", Codetable."Profile_ID" as "profid", Codetable."Appn" as "app", Codetable."Proj" as "prj", Codetable."Resp" as "ra", Codetable."Pcnt" as "perct" from "DBO"."VOUCHER_CODING" Codetable where (Codetable."Contract_Year" in ('14','15','16','17'))) Codetable
DEBUG: SQL Implicit Passthru stmt has been prepared successfully.
ODBC_3: Executed: on connection 1Prepared statement ODBC_2
DEBUG: SQL Implicit Passthru stmt used for fetching data.
ACCESS ENGINE: SQL statement was passed to the DBMS for fetching data.NOTE: Table OLD.TABLE2 created, with 2406 rows and 13 columns.
17 QUIT;NOTE: PROCEDURE SQL used (Total process time):
real time 5.80 secondscpu time 0.21 seconds
SASTRACE DEBUG=DBMS_SELECT
![Page 24: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/24.jpg)
Same query…
QUERY PROCESSED ON SAS
![Page 25: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/25.jpg)
Query Processed on SAS (script)OPTIONS DEBUG=DBMS_SELECT SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;LIBNAME OLD 'L:\BFSPROC\CARSVOUCHERS';
LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;
PROC SQL NOIPASSTHRU;CREATE TABLE old.TABLE2 ASSELECT DISTINCT Contract_Year AS year, Profile_ID AS
profid, Appn AS app, Proj AS prj, Resp AS ra, Pcnt AS perctFROM CARSSQ.VOUCHER_CODING as CodetableWHERE CONTRACT_YEAR IN ('14','15','16','17');
QUIT;
![Page 26: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/26.jpg)
Query Processed on the DBMS (log)9 LIBNAME CARSSQ ODBC DATASRC=FMS_PROD SCHEMA=DBO USER=&SYSUSERID. DBPROMPT=YES;NOTE: Libref CARSSQ was successfully assigned as follows:
Engine: ODBC
11 <PROC SQL statements here>ODBC: AUTOCOMMIT is NO for connection 0ODBC: AUTOCOMMIT turned ON for connection id 0DBMS_SELECT: SELECT * FROM "DBO"."VOUCHER_CODING"
ODBC_1: Prepared: on connection 0SELECT * FROM "DBO"."VOUCHER_CODING"
DBMS_SELECT: SELECT "Contract_Year", "Profile_ID", "Appn", "Proj", "Resp", "Pcnt FROM "DBO"."VOUCHER_CODING" WHERE (("Contract_Year" IN ('14','15','16','17')))
ODBC_2: Prepared: on connection 0SELECT "Contract_Year", "Profile_ID", "Appn", "Proj", "Resp", "Pcnt" FROM"DBO"."VOUCHER_CODING" WHERE (("Contract_Year" IN ('14','15','16','17')))
ODBC_3: Executed: on connection 0Prepared statement ODBC_2NOTE: Table OLD.TABLE2 created, with 2406 rows and 13 columns
17 QUIT;NOTE: PROCEDURE SQL used (Total process time):
real time 9.28 secondscpu time 0.18 seconds
SASTRACE DEBUG=DBMS_SELECT
![Page 27: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/27.jpg)
Effect of Processing Location on Run Time
Method Where Processing Occurred
Real Time (seconds)
No distinct, no implicit pass-through SAS 11.1
Distinct, no implicit pass-through SAS 9.3
Distinct, implicit pass-through DBMS 5.8
![Page 28: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/28.jpg)
Summary• The SAS/ACCESS Libname engine interface
• Easy way to communicate with a DBMS• Relatively easy coding • Engine optimizes queries• Must know triggers to achieve SQL pass‐through
• Edit queries to allow them to pass‐through to DBMS
• Use System Options DEBUG and/or SASTRACE
• Where you process data matters!• Large DBMS may be more efficient than SAS• Large datasets = significant time/resource savings
![Page 29: Johnson - Just Passing Through - SQL Pass Through · • Must know triggers to achieve SQL pass‐through • Edit queries to allow them to pass‐through to DBMS • Use System Options](https://reader033.fdocuments.net/reader033/viewer/2022052713/5b905c6809d3f21c788bcc91/html5/thumbnails/29.jpg)
Misty [email protected]
THANK YOU
SAS and a l l o the r SAS I n s t i t u t e I n c . p rodu c t o r s e r v i c e names a r e r e g i s t e r ed t r a dema r k s o r t r a dema r k s o f SAS I n s t i t u t e I n c . i n t h e USA and o the r coun t r i e s . ® i n d i c a t e s USA r e g i s t r a t i o n .
Othe r b r and and p rodu c t names a r e t r a dema r k s o f t h e i r r e s pe c t i v e compan i e s .