SlideShare a Scribd company logo
1 of 14
Alexandre Marini
Senior IT Consultant
Brazil
Don't make your Informix static -
developers do's and don'ts tips
Don't make your Informix static - developers do's and don'ts
tips
 - Simple code changes can make a huge
impact
 - Some “don'ts” specific cases
 - How to use UDFs in SQL
 - Tips for generic development / work
Agenda
Don't make your Informix static - developers do's and don'ts
tips

Simple code changes can make a huge impact
1) Choose a right data type/validation method
Create table [tabname]
(col1 integer,
col2 char(14),
col3 varchar(50),
col4 char(14),
primary key (cod1)
);
Columns 2 and 4 stores two kinds of records: personal or company ID,
depending on char length.
Don't make your Informix static - developers do's and don'ts
tips

Simple code changes can make a huge impact
- Validation UDR was running in procedure – isnumeric() based
- Going through all 14/11 digits for != [0-9]
- Running into a big table (around 320 K rows)
- 2 columns (cols 2 and 4)
- Data loading procedure: obviously as fast as a turtle!
- Simple line of cast turned the process 89% faster
ge: Col2::decimal(14,0)
Don't make your Informix static - developers do's and don'ts
tips

Simple code changes can make a huge impact
2) Verify your search patterns
Example: An ITIN, or Individual Taxpayer Identification Number, 9-digit
length, beginning with the number "9", formatted like an SSN (NNN-
NN-NNNN).
- searches with like %chars%, or matches *chars*, in an alpha
column with a pattern on the first “n” digits
select count(nmr_lancto)
from recconta
where cdg_fornecedor like "%01838723%" and dat_cancel is null
and nmr_or is null and dat_recebto is null
Don't make your Informix static - developers do's and don'ts
tips

Simple code changes can make a huge impact
- using like '%[digits]%', the cost is very high
- note that used indexes are the same: before and after changes
Estimated Cost: 13476
Estimated # of Rows Returned: 1
1) informix.recconta: INDEX PATH
(1) Index Name: informix.xie12recconta
Index Keys: dat_cancel nmr_or dat_recebto cdg_fornecedor (Key-First) (Serial,
fragments: ALL)
Lower Index Filter: ((informix.recconta.dat_recebto IS NULL AND
informix.recconta.nmr_or IS NULL ) AND informix.recconta.dat_cancel IS NULL )
Index Key Filters: (informix.recconta.cdg_fornecedor LIKE '%01838723%' )
Don't make your Informix static - developers do's and don'ts
tips

Simple code changes can make a huge impact
- rewritten query, just with like '[digits]%', (same begin
pattern)…
select count(nmr_lancto)
from recconta
where cdg_fornecedor like "01838723%" and
dat_cancel is null and nmr_or is null and dat_recebto is null
Estimated Cost: 79
Estimated # of Rows Returned: 1
1) informix.recconta: INDEX PATH
(1) Index Name: informix.xie12recconta
Index Keys: dat_cancel nmr_or dat_recebto cdg_fornecedor (Serial, fragments: ALL)
Lower Index Filter: (((informix.recconta.cdg_fornecedor LIKE '01838723%' AND
informix.recconta.dat_recebto IS NULL ) AND informix.recconta.nmr_or IS NULL ) AND
informix.recconta.dat_cancel IS NULL
Don't make your Informix static - developers do's and don'ts
tips

Simple code changes can make a huge impact
3) Be careful with trigger events – audit trigger example
ORIGINAL CODE:
CREATE TRIGGER [trigger_name] UPDATE on [table_name]
REFERENCING OLD AS o NEW AS n
for each row
if o.column1 != n.column2 then
insert into tbaudit_upd(values…)
end if
end;
RECOMMENDED CODE:
CREATE TRIGGER [trigger_name] UPDATE OF [audit_field] on [table_name]
REFERENCING OLD as o NEW AS n
for each row
WHEN n.column1 != o.column1
insert into tbaudit_upd(values….);
End;
- Focus on the most specific trigger event
Benefits: lower processing avoiding unecessary executions!
Don't make your Informix static - developers do's and don'ts
tips

Some don'ts specific cases
- Avoid DISTINCT, unless extremely needed:
Prefer cleaning and normalizing data, create constraints at the fields,
before insert triggers…
- Avoid *s:
 - define clauses: define abc record like [table].*
 - selects, deletes, into clauses
 - updates: update [table] set [table.]* = record.*
 - inserts clauses without column names
 insert into [table] values (record.*)

A simple schema change, with one added column, will demand lots of
code changing! Time is money!
Don't make your Informix static - developers do's and don'ts
tips
- Avoid using UDFs in WHERE sections

SELECT 'Email sent: ' || email_subject || ' from ' ||
UPPER(email_from) || ' to ' || UPPER(email_to) || ' at ' ||
email_datetime
FROM USU_EMAIL
WHERE UPPER(email_from) =
'ALEXANDRE@MCSOFTWARE.COM.BR'
Estimated Cost: 326
Estimated # of Rows Returned: 500
1) usu_email: SEQUENTIAL SCAN
Filters: UPPER(usu_email.email_from ) =
'ALEXANDRE@MCSOFTWARE.COM.BR
How to use UDFs in SQL
Don't make your Informix static - developers do's and don'ts
tips

How to use UDFs in SQL
- Two possibilities:
1) Normalize data before input
2) Create a functional index
CREATE FUNCTION toUpper(name VARCHAR(100))
RETURNS VARCHAR(100) WITH (NOT
VARIANT);
RETURN upper( name );
END FUNCTION;
CREATE INDEX idx_upper_email ON USU_EMAIL
( toUpper(email_from) );
Don't make your Informix static - developers do's and don'ts
tips

How to use UDFs in SQL
- Running the same query again:
SELECT 'Email sent: ' || email_subject || ' from ' ||
UPPER(email_from) || ' to ' || UPPER(email_to) || ' at ' || email_datetime
FROM USU_EMAIL
WHERE UPPER(email_from) = `ALEXANDRE@MCSOFTWARE.COM.BR'
Estimated Cost: 2
Estimated # of Rows Returned: 2
1) usu_email: INDEX PATH
(1) Index Name: idx_upper_email
Index Keys: toupper(email_de) (Serial, fragments: ALL)
Lower Index Filter: toupper(usu_email.email_de)=
`ALEXANDRE@MCSOFTWARE.COM.BR'
 UDRs are shown in sqexplain output:
 UDRs in query:
--------------
UDR id : 454
UDR name: toupper
Don't make your Informix static - developers do's and don'ts
tips

Tips for generic development / work
- Simplifying (KISS), Reuse, Documenting


 - Don't try to reinvent the wheel. Database
manager systems have UDRs to do whatever you
need


 - Work together with your DBA. He must be
boring, but he can save your time, brains, and
provide you several tech tips
Don't make your Informix static - developers do's and don'ts
tips

Questions?
alexandre@mcsoftware.com.br

More Related Content

Viewers also liked

Why Smart Meters Need Informix TimeSeries
Why Smart Meters Need Informix TimeSeriesWhy Smart Meters Need Informix TimeSeries
Why Smart Meters Need Informix TimeSeriesIBM Sverige
 
UGIF 12 2010 - informix 11.7 - The Beginning of the Next Decade
UGIF 12 2010 - informix 11.7 - The Beginning of the Next DecadeUGIF 12 2010 - informix 11.7 - The Beginning of the Next Decade
UGIF 12 2010 - informix 11.7 - The Beginning of the Next DecadeUGIF
 
IBM Informix dynamic server and websphere MQ integration
IBM Informix dynamic server and websphere MQ  integrationIBM Informix dynamic server and websphere MQ  integration
IBM Informix dynamic server and websphere MQ integrationKeshav Murthy
 
Ibm informix security functionality overview
Ibm informix security functionality overviewIbm informix security functionality overview
Ibm informix security functionality overviewBeGooden-IT Consulting
 
Using Informix Warehouse Accelerator with Informix high availability and scal...
Using Informix Warehouse Accelerator with Informix high availability and scal...Using Informix Warehouse Accelerator with Informix high availability and scal...
Using Informix Warehouse Accelerator with Informix high availability and scal...Keshav Murthy
 
IIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into RIIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into RKevin Smith
 
Informix - The Ideal Database for IoT
Informix - The Ideal Database for IoTInformix - The Ideal Database for IoT
Informix - The Ideal Database for IoTPradeep Natarajan
 
IBM Informix - What's new in 12.10.xc7
IBM Informix - What's new in 12.10.xc7IBM Informix - What's new in 12.10.xc7
IBM Informix - What's new in 12.10.xc7Pradeep Natarajan
 
Security best practices for informix
Security best practices for informixSecurity best practices for informix
Security best practices for informixIBM_Info_Management
 
Informix internet of things
Informix   internet of thingsInformix   internet of things
Informix internet of thingsIBM Sverige
 
IoT / M2M Solutions with Informix in the IoT Gateway
IoT / M2M Solutions with Informix in the IoT GatewayIoT / M2M Solutions with Informix in the IoT Gateway
IoT / M2M Solutions with Informix in the IoT GatewayEurotech
 

Viewers also liked (11)

Why Smart Meters Need Informix TimeSeries
Why Smart Meters Need Informix TimeSeriesWhy Smart Meters Need Informix TimeSeries
Why Smart Meters Need Informix TimeSeries
 
UGIF 12 2010 - informix 11.7 - The Beginning of the Next Decade
UGIF 12 2010 - informix 11.7 - The Beginning of the Next DecadeUGIF 12 2010 - informix 11.7 - The Beginning of the Next Decade
UGIF 12 2010 - informix 11.7 - The Beginning of the Next Decade
 
IBM Informix dynamic server and websphere MQ integration
IBM Informix dynamic server and websphere MQ  integrationIBM Informix dynamic server and websphere MQ  integration
IBM Informix dynamic server and websphere MQ integration
 
Ibm informix security functionality overview
Ibm informix security functionality overviewIbm informix security functionality overview
Ibm informix security functionality overview
 
Using Informix Warehouse Accelerator with Informix high availability and scal...
Using Informix Warehouse Accelerator with Informix high availability and scal...Using Informix Warehouse Accelerator with Informix high availability and scal...
Using Informix Warehouse Accelerator with Informix high availability and scal...
 
IIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into RIIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into R
 
Informix - The Ideal Database for IoT
Informix - The Ideal Database for IoTInformix - The Ideal Database for IoT
Informix - The Ideal Database for IoT
 
IBM Informix - What's new in 12.10.xc7
IBM Informix - What's new in 12.10.xc7IBM Informix - What's new in 12.10.xc7
IBM Informix - What's new in 12.10.xc7
 
Security best practices for informix
Security best practices for informixSecurity best practices for informix
Security best practices for informix
 
Informix internet of things
Informix   internet of thingsInformix   internet of things
Informix internet of things
 
IoT / M2M Solutions with Informix in the IoT Gateway
IoT / M2M Solutions with Informix in the IoT GatewayIoT / M2M Solutions with Informix in the IoT Gateway
IoT / M2M Solutions with Informix in the IoT Gateway
 

More from Alexandre Marini

Onde está Informix - Where is Informix (traduzido e atualizado)
Onde está Informix - Where is Informix (traduzido e atualizado)Onde está Informix - Where is Informix (traduzido e atualizado)
Onde está Informix - Where is Informix (traduzido e atualizado)Alexandre Marini
 
PoC of IBM Informix Warehouse Accelerator and Storage Optimization Feature
PoC of IBM Informix Warehouse Accelerator and Storage Optimization FeaturePoC of IBM Informix Warehouse Accelerator and Storage Optimization Feature
PoC of IBM Informix Warehouse Accelerator and Storage Optimization FeatureAlexandre Marini
 
Itges1009 Informix Sql Ms 1 Traduzido
Itges1009 Informix Sql Ms 1 TraduzidoItges1009 Informix Sql Ms 1 Traduzido
Itges1009 Informix Sql Ms 1 TraduzidoAlexandre Marini
 
Itg1009 Informix Sql Ms Traduzido
Itg1009 Informix Sql Ms TraduzidoItg1009 Informix Sql Ms Traduzido
Itg1009 Informix Sql Ms TraduzidoAlexandre Marini
 

More from Alexandre Marini (6)

Onde está Informix - Where is Informix (traduzido e atualizado)
Onde está Informix - Where is Informix (traduzido e atualizado)Onde está Informix - Where is Informix (traduzido e atualizado)
Onde está Informix - Where is Informix (traduzido e atualizado)
 
PoC of IBM Informix Warehouse Accelerator and Storage Optimization Feature
PoC of IBM Informix Warehouse Accelerator and Storage Optimization FeaturePoC of IBM Informix Warehouse Accelerator and Storage Optimization Feature
PoC of IBM Informix Warehouse Accelerator and Storage Optimization Feature
 
Itges1009 Informix Sql Ms 1 Traduzido
Itges1009 Informix Sql Ms 1 TraduzidoItges1009 Informix Sql Ms 1 Traduzido
Itges1009 Informix Sql Ms 1 Traduzido
 
Itg1009 Informix Sql Ms Traduzido
Itg1009 Informix Sql Ms TraduzidoItg1009 Informix Sql Ms Traduzido
Itg1009 Informix Sql Ms Traduzido
 
2 Informix Introduction
2 Informix Introduction2 Informix Introduction
2 Informix Introduction
 
1 Ids On Campus V3a
1 Ids On Campus V3a1 Ids On Campus V3a
1 Ids On Campus V3a
 

Recently uploaded

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 

Recently uploaded (20)

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 

Don't make your Informix static - developers do's and don'ts tips

  • 1. Alexandre Marini Senior IT Consultant Brazil Don't make your Informix static - developers do's and don'ts tips
  • 2. Don't make your Informix static - developers do's and don'ts tips  - Simple code changes can make a huge impact  - Some “don'ts” specific cases  - How to use UDFs in SQL  - Tips for generic development / work Agenda
  • 3. Don't make your Informix static - developers do's and don'ts tips  Simple code changes can make a huge impact 1) Choose a right data type/validation method Create table [tabname] (col1 integer, col2 char(14), col3 varchar(50), col4 char(14), primary key (cod1) ); Columns 2 and 4 stores two kinds of records: personal or company ID, depending on char length.
  • 4. Don't make your Informix static - developers do's and don'ts tips  Simple code changes can make a huge impact - Validation UDR was running in procedure – isnumeric() based - Going through all 14/11 digits for != [0-9] - Running into a big table (around 320 K rows) - 2 columns (cols 2 and 4) - Data loading procedure: obviously as fast as a turtle! - Simple line of cast turned the process 89% faster ge: Col2::decimal(14,0)
  • 5. Don't make your Informix static - developers do's and don'ts tips  Simple code changes can make a huge impact 2) Verify your search patterns Example: An ITIN, or Individual Taxpayer Identification Number, 9-digit length, beginning with the number "9", formatted like an SSN (NNN- NN-NNNN). - searches with like %chars%, or matches *chars*, in an alpha column with a pattern on the first “n” digits select count(nmr_lancto) from recconta where cdg_fornecedor like "%01838723%" and dat_cancel is null and nmr_or is null and dat_recebto is null
  • 6. Don't make your Informix static - developers do's and don'ts tips  Simple code changes can make a huge impact - using like '%[digits]%', the cost is very high - note that used indexes are the same: before and after changes Estimated Cost: 13476 Estimated # of Rows Returned: 1 1) informix.recconta: INDEX PATH (1) Index Name: informix.xie12recconta Index Keys: dat_cancel nmr_or dat_recebto cdg_fornecedor (Key-First) (Serial, fragments: ALL) Lower Index Filter: ((informix.recconta.dat_recebto IS NULL AND informix.recconta.nmr_or IS NULL ) AND informix.recconta.dat_cancel IS NULL ) Index Key Filters: (informix.recconta.cdg_fornecedor LIKE '%01838723%' )
  • 7. Don't make your Informix static - developers do's and don'ts tips  Simple code changes can make a huge impact - rewritten query, just with like '[digits]%', (same begin pattern)… select count(nmr_lancto) from recconta where cdg_fornecedor like "01838723%" and dat_cancel is null and nmr_or is null and dat_recebto is null Estimated Cost: 79 Estimated # of Rows Returned: 1 1) informix.recconta: INDEX PATH (1) Index Name: informix.xie12recconta Index Keys: dat_cancel nmr_or dat_recebto cdg_fornecedor (Serial, fragments: ALL) Lower Index Filter: (((informix.recconta.cdg_fornecedor LIKE '01838723%' AND informix.recconta.dat_recebto IS NULL ) AND informix.recconta.nmr_or IS NULL ) AND informix.recconta.dat_cancel IS NULL
  • 8. Don't make your Informix static - developers do's and don'ts tips  Simple code changes can make a huge impact 3) Be careful with trigger events – audit trigger example ORIGINAL CODE: CREATE TRIGGER [trigger_name] UPDATE on [table_name] REFERENCING OLD AS o NEW AS n for each row if o.column1 != n.column2 then insert into tbaudit_upd(values…) end if end; RECOMMENDED CODE: CREATE TRIGGER [trigger_name] UPDATE OF [audit_field] on [table_name] REFERENCING OLD as o NEW AS n for each row WHEN n.column1 != o.column1 insert into tbaudit_upd(values….); End; - Focus on the most specific trigger event Benefits: lower processing avoiding unecessary executions!
  • 9. Don't make your Informix static - developers do's and don'ts tips  Some don'ts specific cases - Avoid DISTINCT, unless extremely needed: Prefer cleaning and normalizing data, create constraints at the fields, before insert triggers… - Avoid *s:  - define clauses: define abc record like [table].*  - selects, deletes, into clauses  - updates: update [table] set [table.]* = record.*  - inserts clauses without column names  insert into [table] values (record.*)  A simple schema change, with one added column, will demand lots of code changing! Time is money!
  • 10. Don't make your Informix static - developers do's and don'ts tips - Avoid using UDFs in WHERE sections  SELECT 'Email sent: ' || email_subject || ' from ' || UPPER(email_from) || ' to ' || UPPER(email_to) || ' at ' || email_datetime FROM USU_EMAIL WHERE UPPER(email_from) = 'ALEXANDRE@MCSOFTWARE.COM.BR' Estimated Cost: 326 Estimated # of Rows Returned: 500 1) usu_email: SEQUENTIAL SCAN Filters: UPPER(usu_email.email_from ) = 'ALEXANDRE@MCSOFTWARE.COM.BR How to use UDFs in SQL
  • 11. Don't make your Informix static - developers do's and don'ts tips  How to use UDFs in SQL - Two possibilities: 1) Normalize data before input 2) Create a functional index CREATE FUNCTION toUpper(name VARCHAR(100)) RETURNS VARCHAR(100) WITH (NOT VARIANT); RETURN upper( name ); END FUNCTION; CREATE INDEX idx_upper_email ON USU_EMAIL ( toUpper(email_from) );
  • 12. Don't make your Informix static - developers do's and don'ts tips  How to use UDFs in SQL - Running the same query again: SELECT 'Email sent: ' || email_subject || ' from ' || UPPER(email_from) || ' to ' || UPPER(email_to) || ' at ' || email_datetime FROM USU_EMAIL WHERE UPPER(email_from) = `ALEXANDRE@MCSOFTWARE.COM.BR' Estimated Cost: 2 Estimated # of Rows Returned: 2 1) usu_email: INDEX PATH (1) Index Name: idx_upper_email Index Keys: toupper(email_de) (Serial, fragments: ALL) Lower Index Filter: toupper(usu_email.email_de)= `ALEXANDRE@MCSOFTWARE.COM.BR'  UDRs are shown in sqexplain output:  UDRs in query: -------------- UDR id : 454 UDR name: toupper
  • 13. Don't make your Informix static - developers do's and don'ts tips  Tips for generic development / work - Simplifying (KISS), Reuse, Documenting    - Don't try to reinvent the wheel. Database manager systems have UDRs to do whatever you need    - Work together with your DBA. He must be boring, but he can save your time, brains, and provide you several tech tips
  • 14. Don't make your Informix static - developers do's and don'ts tips  Questions? alexandre@mcsoftware.com.br