SlideShare a Scribd company logo
Lunch + Learn
SQL Tips + Tricks for Developers
Victor Szoltysek
July / 2016
Tables + Indexes
Common Mistakes
Not closing resources
• always using finally block / try-resources
finally{
sql1.close();
sql2.close();
}
@Cleanup
Resource someClosableResource;
Missing Indexes
• Not important for small tables
• Huge potential performance improvements — x10000
• Watch out for incorrect index usage
• MSSQL Server will recommend indexes
• ORMs don’t create indexes!!!!
SELECT *
FROM someTable
WHERE someColumn
LIKE ‘%stringInMiddle%’
SQL Tips + Tricks for Developers
SQL Injection
SQL Injection - Mitigation
• Never EVER use concatenated SQL strings in your
prod applications
• Use Parametrized Statements
Not using Transactions when
Needed
• Transaction :
• Logical Atomic Unit of Work
• All or nothing (even if database gets interrupted)
• Solution for A/B
• Spring @Transactional Annotation
Null misunderstandings!
• NULL == NULL <— not true
• NULL != NULL <— also not true
• NULL != “something” <— ALSO not true
• Empty Strings become Null in Oracle!!
N+1 AntiPattern
• Minimize SQL Traffic!! , Let SQL perform joins,
Network is slow
• Use SQL Count instead of getting all rows and
counting at backend
-- Get all Mobile Vendors
SELECT * FROM MobileVendor;
-- For each MobileVendor, get PhoneModel details
SELECT * FROM PhoneModel WHERE MobileVendor.vendorId=?
Stale Statistics
• Database keeps track of statistics about table data
to help to optimize how it executes queries
• Significant changes to data, can make these
statistics temporarily invalid, and can lead to poor
execution
• Only important with large DB changes, i.e. full
refresh
Tools
Spring Data - Auto
Generated Repositories
Intellij Ultimate SQL Support
VirtualBox + Windows + SQL Server
Express + Mangement Studio
Database Versioning
DBDeploy
Different SQL Databases
SQL Server Oracle Postgres MySQL Firebird H2
Single Cross
Platform
Deployable
No No No No No Yes
Embedded
Support
No No No No Yes Yes
InMemory
Support
No No No Yes No Yes
Free No No Yes Yes Yes Yes
Cross Platform No Yes Yes Yes Yes Yes
InMemory / Embedded /
Java Databases
String connectionString =
"jdbc:h2:mem:inMemoryDb;DB_CLOSE_DELAY=-1"
Awesome for Testing!!!
Most commonly used SQL
database?
Explain Plans
Groovy SQL Support
SQL Tips + Tricks for Developers
ORMs
• Great for Greenfield / CRUD apps
• Easy to go from Object Model to SQL Model
• Can get difficult to create Object Model from
existing SQL Model
• “ORMS are the Vietnam of Computer Science”
NoSQL vs SQL vs NewSQL
• NoSQL did not replace SQL, but is an alternative
• Relational / Structured Data is still create for SQL
DB’s
• NewSQL!! Modern SQL alternatives
Log4J JDBC Appender
SQL Metadata
SELECT 

    t.NAME AS TableName,

    p.rows AS RowCounts,

    (SUM(a.total_pages) * 8 / 1064) AS TotalSpaceMB

FROM 

    sys.tables t

INNER JOIN 

    sys.schemas s ON s.schema_id = t.schema_id

INNER JOIN      

    sys.indexes i ON t.OBJECT_ID = i.object_id

INNER JOIN 

    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id

INNER JOIN 

    sys.allocation_units a ON p.partition_id = a.container_id

WHERE 

    t.NAME NOT LIKE 'dt%'    -- filter out system tables for diagramming

    AND t.is_ms_shipped = 0

    AND i.OBJECT_ID > 255 

GROUP BY 

    t.Name, s.Name, p.Rows

ORDER BY 

    p.Rows desc
Table Analysis
Table Row Count Size MB
agreement_customer 1039293 103
pricing_results 378520 189
sales_history 378520 40
price_rule 256814 26
base_value 252687 19
customer 32754 3
product 19525 1
product_price 19525 5
agreement_product 15105 1
price_rule_flag 7656 0
price_rule_header 2552 0
min_max_rule 292 0
DATABASECHANGEL
OG
61 0
sub_price_rule 29 0
Ad

More Related Content

What's hot (19)

Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
Davide Mauri
 
U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)
Michael Rys
 
Rails best practices
Rails best practicesRails best practices
Rails best practices
Achintya Kumar
 
An introduction to mysql Performance Optimization (2008)
An introduction to mysql Performance Optimization (2008)An introduction to mysql Performance Optimization (2008)
An introduction to mysql Performance Optimization (2008)
lmrei
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
Gianluca Sartori
 
SQL vs NoSQL
SQL vs NoSQLSQL vs NoSQL
SQL vs NoSQL
Jacinto Limjap
 
Effect systems in scala: beyond flatmap
Effect systems in scala: beyond flatmapEffect systems in scala: beyond flatmap
Effect systems in scala: beyond flatmap
Joost de Vries
 
JavaScript Fundamentals
JavaScript FundamentalsJavaScript Fundamentals
JavaScript Fundamentals
Lasantha Bandara
 
Optimizing Java Performance
Optimizing Java PerformanceOptimizing Java Performance
Optimizing Java Performance
Konstantin Pavlov
 
Data mining tools for excel and sql server
Data mining tools for excel and sql serverData mining tools for excel and sql server
Data mining tools for excel and sql server
Sayed Ahmed
 
Data Abstraction for Large Web Applications
Data Abstraction for Large Web ApplicationsData Abstraction for Large Web Applications
Data Abstraction for Large Web Applications
brandonsavage
 
Building 1 million predictions per second using SQL-R
Building 1 million predictions per second using SQL-RBuilding 1 million predictions per second using SQL-R
Building 1 million predictions per second using SQL-R
Amit Banerjee
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
MediaMongrels Ltd
 
Doctrine Data migrations | May 2017
Doctrine Data migrations | May 2017Doctrine Data migrations | May 2017
Doctrine Data migrations | May 2017
Petr Bechyně
 
U-SQL Learning Resources (SQLBits 2016)
U-SQL Learning Resources (SQLBits 2016)U-SQL Learning Resources (SQLBits 2016)
U-SQL Learning Resources (SQLBits 2016)
Michael Rys
 
Unit testing hippo
Unit testing hippoUnit testing hippo
Unit testing hippo
Ebrahim Aharpour
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
Syed Ashraf Ullah
 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects Optimization
WO Community
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
Mike Slinn
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
Davide Mauri
 
U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)
Michael Rys
 
An introduction to mysql Performance Optimization (2008)
An introduction to mysql Performance Optimization (2008)An introduction to mysql Performance Optimization (2008)
An introduction to mysql Performance Optimization (2008)
lmrei
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
Gianluca Sartori
 
Effect systems in scala: beyond flatmap
Effect systems in scala: beyond flatmapEffect systems in scala: beyond flatmap
Effect systems in scala: beyond flatmap
Joost de Vries
 
Data mining tools for excel and sql server
Data mining tools for excel and sql serverData mining tools for excel and sql server
Data mining tools for excel and sql server
Sayed Ahmed
 
Data Abstraction for Large Web Applications
Data Abstraction for Large Web ApplicationsData Abstraction for Large Web Applications
Data Abstraction for Large Web Applications
brandonsavage
 
Building 1 million predictions per second using SQL-R
Building 1 million predictions per second using SQL-RBuilding 1 million predictions per second using SQL-R
Building 1 million predictions per second using SQL-R
Amit Banerjee
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
MediaMongrels Ltd
 
Doctrine Data migrations | May 2017
Doctrine Data migrations | May 2017Doctrine Data migrations | May 2017
Doctrine Data migrations | May 2017
Petr Bechyně
 
U-SQL Learning Resources (SQLBits 2016)
U-SQL Learning Resources (SQLBits 2016)U-SQL Learning Resources (SQLBits 2016)
U-SQL Learning Resources (SQLBits 2016)
Michael Rys
 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects Optimization
WO Community
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
Mike Slinn
 

Similar to SQL Tips + Tricks for Developers (20)

Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql server
Chris Adkin
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should know
Kevin Kline
 
Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptx
QuyVo27
 
Revision
RevisionRevision
Revision
David Sherlock
 
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptxCSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
noshinnawar31
 
Enterprise NoSQL: Silver Bullet or Poison Pill
Enterprise NoSQL: Silver Bullet or Poison PillEnterprise NoSQL: Silver Bullet or Poison Pill
Enterprise NoSQL: Silver Bullet or Poison Pill
Billy Newport
 
White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...
Jeff Jacobs
 
Schema less table & dynamic schema
Schema less table & dynamic schemaSchema less table & dynamic schema
Schema less table & dynamic schema
Davide Mauri
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
nkarag
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
Davide Mauri
 
Conquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard queryConquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard query
Justin Swanhart
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
Kazuhiro Sera
 
Geek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringGeek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database Mirroring
IDERA Software
 
A. Sarkissian Death of Relational Databases
A. Sarkissian Death of Relational DatabasesA. Sarkissian Death of Relational Databases
A. Sarkissian Death of Relational Databases
Mediabistro
 
PHP - Introduction to Advanced SQL
PHP - Introduction to Advanced SQLPHP - Introduction to Advanced SQL
PHP - Introduction to Advanced SQL
Vibrant Technologies & Computers
 
Active Record PowerPoint
Active Record PowerPointActive Record PowerPoint
Active Record PowerPoint
Elizabeth Cruz
 
Breaking data
Breaking dataBreaking data
Breaking data
Terry Bunio
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
scalaconfjp
 
Golden Hammer - Shawn Oden
Golden Hammer - Shawn OdenGolden Hammer - Shawn Oden
Golden Hammer - Shawn Oden
Ortus Solutions, Corp
 
Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql server
Chris Adkin
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should know
Kevin Kline
 
Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptx
QuyVo27
 
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptxCSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
noshinnawar31
 
Enterprise NoSQL: Silver Bullet or Poison Pill
Enterprise NoSQL: Silver Bullet or Poison PillEnterprise NoSQL: Silver Bullet or Poison Pill
Enterprise NoSQL: Silver Bullet or Poison Pill
Billy Newport
 
White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...
Jeff Jacobs
 
Schema less table & dynamic schema
Schema less table & dynamic schemaSchema less table & dynamic schema
Schema less table & dynamic schema
Davide Mauri
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
nkarag
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
Davide Mauri
 
Conquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard queryConquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard query
Justin Swanhart
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
Kazuhiro Sera
 
Geek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringGeek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database Mirroring
IDERA Software
 
A. Sarkissian Death of Relational Databases
A. Sarkissian Death of Relational DatabasesA. Sarkissian Death of Relational Databases
A. Sarkissian Death of Relational Databases
Mediabistro
 
Active Record PowerPoint
Active Record PowerPointActive Record PowerPoint
Active Record PowerPoint
Elizabeth Cruz
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
scalaconfjp
 
Ad

More from VictorSzoltysek (20)

The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...
The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...
The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...
VictorSzoltysek
 
Java on AWS Without the Headaches - Fast Builds, Cheap Deploys, No Kubernetes
Java on AWS Without the Headaches - Fast Builds, Cheap Deploys, No KubernetesJava on AWS Without the Headaches - Fast Builds, Cheap Deploys, No Kubernetes
Java on AWS Without the Headaches - Fast Builds, Cheap Deploys, No Kubernetes
VictorSzoltysek
 
Demystifying GitHub Actions - Harnessing the power of automation to streamlin...
Demystifying GitHub Actions - Harnessing the power of automation to streamlin...Demystifying GitHub Actions - Harnessing the power of automation to streamlin...
Demystifying GitHub Actions - Harnessing the power of automation to streamlin...
VictorSzoltysek
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
VictorSzoltysek
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
VictorSzoltysek
 
Simplified DevOps Bliss -with OpenAI API
Simplified DevOps Bliss -with OpenAI APISimplified DevOps Bliss -with OpenAI API
Simplified DevOps Bliss -with OpenAI API
VictorSzoltysek
 
From SpaceX Launch Pads to Rapid Deployments
From SpaceX Launch Pads to Rapid DeploymentsFrom SpaceX Launch Pads to Rapid Deployments
From SpaceX Launch Pads to Rapid Deployments
VictorSzoltysek
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
VictorSzoltysek
 
Driving Process Improvements - A Guided Approach to Running Effective Retrosp...
Driving Process Improvements - A Guided Approach to Running Effective Retrosp...Driving Process Improvements - A Guided Approach to Running Effective Retrosp...
Driving Process Improvements - A Guided Approach to Running Effective Retrosp...
VictorSzoltysek
 
Spaceships, Pull Requests and Feature Branching - A Principles-Based approac...
Spaceships, Pull Requests and Feature Branching  - A Principles-Based approac...Spaceships, Pull Requests and Feature Branching  - A Principles-Based approac...
Spaceships, Pull Requests and Feature Branching - A Principles-Based approac...
VictorSzoltysek
 
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
VictorSzoltysek
 
Real-World Application Observability - 11 Practical Developer Focused Tips
Real-World Application Observability - 11 Practical Developer Focused TipsReal-World Application Observability - 11 Practical Developer Focused Tips
Real-World Application Observability - 11 Practical Developer Focused Tips
VictorSzoltysek
 
Victor's Awesome Retro Deck
Victor's Awesome Retro DeckVictor's Awesome Retro Deck
Victor's Awesome Retro Deck
VictorSzoltysek
 
Software Development in Internet Memes
Software Development in Internet MemesSoftware Development in Internet Memes
Software Development in Internet Memes
VictorSzoltysek
 
Big Bangs, Monorails and Microservices - Feb 2020
Big Bangs, Monorails and Microservices - Feb 2020Big Bangs, Monorails and Microservices - Feb 2020
Big Bangs, Monorails and Microservices - Feb 2020
VictorSzoltysek
 
Less is more the 7 wastes of lean software development
Less is more   the 7 wastes of lean software developmentLess is more   the 7 wastes of lean software development
Less is more the 7 wastes of lean software development
VictorSzoltysek
 
Modern day jvm controversies
Modern day jvm controversiesModern day jvm controversies
Modern day jvm controversies
VictorSzoltysek
 
The Future of Java - and a look at the evolution of programming languages
The Future of Java - and a look at the evolution of programming languagesThe Future of Java - and a look at the evolution of programming languages
The Future of Java - and a look at the evolution of programming languages
VictorSzoltysek
 
Client Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future ReplacementClient Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future Replacement
VictorSzoltysek
 
The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...
The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...
The Gold Jacket Journey - How I passed 12 AWS Certs without Burning Out (and ...
VictorSzoltysek
 
Java on AWS Without the Headaches - Fast Builds, Cheap Deploys, No Kubernetes
Java on AWS Without the Headaches - Fast Builds, Cheap Deploys, No KubernetesJava on AWS Without the Headaches - Fast Builds, Cheap Deploys, No Kubernetes
Java on AWS Without the Headaches - Fast Builds, Cheap Deploys, No Kubernetes
VictorSzoltysek
 
Demystifying GitHub Actions - Harnessing the power of automation to streamlin...
Demystifying GitHub Actions - Harnessing the power of automation to streamlin...Demystifying GitHub Actions - Harnessing the power of automation to streamlin...
Demystifying GitHub Actions - Harnessing the power of automation to streamlin...
VictorSzoltysek
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
VictorSzoltysek
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
VictorSzoltysek
 
Simplified DevOps Bliss -with OpenAI API
Simplified DevOps Bliss -with OpenAI APISimplified DevOps Bliss -with OpenAI API
Simplified DevOps Bliss -with OpenAI API
VictorSzoltysek
 
From SpaceX Launch Pads to Rapid Deployments
From SpaceX Launch Pads to Rapid DeploymentsFrom SpaceX Launch Pads to Rapid Deployments
From SpaceX Launch Pads to Rapid Deployments
VictorSzoltysek
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
VictorSzoltysek
 
Driving Process Improvements - A Guided Approach to Running Effective Retrosp...
Driving Process Improvements - A Guided Approach to Running Effective Retrosp...Driving Process Improvements - A Guided Approach to Running Effective Retrosp...
Driving Process Improvements - A Guided Approach to Running Effective Retrosp...
VictorSzoltysek
 
Spaceships, Pull Requests and Feature Branching - A Principles-Based approac...
Spaceships, Pull Requests and Feature Branching  - A Principles-Based approac...Spaceships, Pull Requests and Feature Branching  - A Principles-Based approac...
Spaceships, Pull Requests and Feature Branching - A Principles-Based approac...
VictorSzoltysek
 
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
VictorSzoltysek
 
Real-World Application Observability - 11 Practical Developer Focused Tips
Real-World Application Observability - 11 Practical Developer Focused TipsReal-World Application Observability - 11 Practical Developer Focused Tips
Real-World Application Observability - 11 Practical Developer Focused Tips
VictorSzoltysek
 
Victor's Awesome Retro Deck
Victor's Awesome Retro DeckVictor's Awesome Retro Deck
Victor's Awesome Retro Deck
VictorSzoltysek
 
Software Development in Internet Memes
Software Development in Internet MemesSoftware Development in Internet Memes
Software Development in Internet Memes
VictorSzoltysek
 
Big Bangs, Monorails and Microservices - Feb 2020
Big Bangs, Monorails and Microservices - Feb 2020Big Bangs, Monorails and Microservices - Feb 2020
Big Bangs, Monorails and Microservices - Feb 2020
VictorSzoltysek
 
Less is more the 7 wastes of lean software development
Less is more   the 7 wastes of lean software developmentLess is more   the 7 wastes of lean software development
Less is more the 7 wastes of lean software development
VictorSzoltysek
 
Modern day jvm controversies
Modern day jvm controversiesModern day jvm controversies
Modern day jvm controversies
VictorSzoltysek
 
The Future of Java - and a look at the evolution of programming languages
The Future of Java - and a look at the evolution of programming languagesThe Future of Java - and a look at the evolution of programming languages
The Future of Java - and a look at the evolution of programming languages
VictorSzoltysek
 
Client Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future ReplacementClient Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future Replacement
VictorSzoltysek
 
Ad

Recently uploaded (20)

Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 

SQL Tips + Tricks for Developers

  • 1. Lunch + Learn SQL Tips + Tricks for Developers Victor Szoltysek July / 2016
  • 4. Not closing resources • always using finally block / try-resources finally{ sql1.close(); sql2.close(); } @Cleanup Resource someClosableResource;
  • 5. Missing Indexes • Not important for small tables • Huge potential performance improvements — x10000 • Watch out for incorrect index usage • MSSQL Server will recommend indexes • ORMs don’t create indexes!!!! SELECT * FROM someTable WHERE someColumn LIKE ‘%stringInMiddle%’
  • 8. SQL Injection - Mitigation • Never EVER use concatenated SQL strings in your prod applications • Use Parametrized Statements
  • 9. Not using Transactions when Needed • Transaction : • Logical Atomic Unit of Work • All or nothing (even if database gets interrupted) • Solution for A/B • Spring @Transactional Annotation
  • 10. Null misunderstandings! • NULL == NULL <— not true • NULL != NULL <— also not true • NULL != “something” <— ALSO not true • Empty Strings become Null in Oracle!!
  • 11. N+1 AntiPattern • Minimize SQL Traffic!! , Let SQL perform joins, Network is slow • Use SQL Count instead of getting all rows and counting at backend -- Get all Mobile Vendors SELECT * FROM MobileVendor; -- For each MobileVendor, get PhoneModel details SELECT * FROM PhoneModel WHERE MobileVendor.vendorId=?
  • 12. Stale Statistics • Database keeps track of statistics about table data to help to optimize how it executes queries • Significant changes to data, can make these statistics temporarily invalid, and can lead to poor execution • Only important with large DB changes, i.e. full refresh
  • 13. Tools
  • 14. Spring Data - Auto Generated Repositories
  • 16. VirtualBox + Windows + SQL Server Express + Mangement Studio
  • 18. Different SQL Databases SQL Server Oracle Postgres MySQL Firebird H2 Single Cross Platform Deployable No No No No No Yes Embedded Support No No No No Yes Yes InMemory Support No No No Yes No Yes Free No No Yes Yes Yes Yes Cross Platform No Yes Yes Yes Yes Yes
  • 19. InMemory / Embedded / Java Databases String connectionString = "jdbc:h2:mem:inMemoryDb;DB_CLOSE_DELAY=-1" Awesome for Testing!!!
  • 20. Most commonly used SQL database?
  • 24. ORMs • Great for Greenfield / CRUD apps • Easy to go from Object Model to SQL Model • Can get difficult to create Object Model from existing SQL Model • “ORMS are the Vietnam of Computer Science”
  • 25. NoSQL vs SQL vs NewSQL • NoSQL did not replace SQL, but is an alternative • Relational / Structured Data is still create for SQL DB’s • NewSQL!! Modern SQL alternatives
  • 27. SQL Metadata SELECT      t.NAME AS TableName,     p.rows AS RowCounts,     (SUM(a.total_pages) * 8 / 1064) AS TotalSpaceMB FROM      sys.tables t INNER JOIN      sys.schemas s ON s.schema_id = t.schema_id INNER JOIN           sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN      sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id INNER JOIN      sys.allocation_units a ON p.partition_id = a.container_id WHERE      t.NAME NOT LIKE 'dt%'    -- filter out system tables for diagramming     AND t.is_ms_shipped = 0     AND i.OBJECT_ID > 255  GROUP BY      t.Name, s.Name, p.Rows ORDER BY      p.Rows desc
  • 28. Table Analysis Table Row Count Size MB agreement_customer 1039293 103 pricing_results 378520 189 sales_history 378520 40 price_rule 256814 26 base_value 252687 19 customer 32754 3 product 19525 1 product_price 19525 5 agreement_product 15105 1 price_rule_flag 7656 0 price_rule_header 2552 0 min_max_rule 292 0 DATABASECHANGEL OG 61 0 sub_price_rule 29 0