Instant Download Refactoring Legacy T-SQL for Improved Performance 1st Edition Lisa Bohm PDF All Chapters
Instant Download Refactoring Legacy T-SQL for Improved Performance 1st Edition Lisa Bohm PDF All Chapters
com
https://ebookmeta.com/product/refactoring-legacy-t-sql-for-
improved-performance-1st-edition-lisa-bohm/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/legacy-the-netherworld-academy-1-1st-
edition-lisa-cardwell/
ebookmeta.com
https://ebookmeta.com/product/on-middle-ground-a-history-of-the-jews-
of-baltimore-eric-l-goldstein/
ebookmeta.com
A Dark Matter 1st Edition Doug Johnstone
https://ebookmeta.com/product/a-dark-matter-1st-edition-doug-
johnstone/
ebookmeta.com
https://ebookmeta.com/product/languaging-diversity-volume-3-language-
s-and-power-1st-edition-elena-di-giovanni/
ebookmeta.com
https://ebookmeta.com/product/the-social-life-of-hagiography-in-the-
merovingian-kingdom-kreiner/
ebookmeta.com
https://ebookmeta.com/product/the-school-of-hillah-and-the-formation-
of-twelver-shi-i-islamic-tradition-1st-edition-aun-hasan-ali/
ebookmeta.com
https://ebookmeta.com/product/savannah-mafia-1-cruel-prince-1st-
edition-m-a-lee/
ebookmeta.com
Kronos Rising Purgatory A Fast Paced Sci Fi Suspense
Thriller Book 6 in the Kronos Rising series 1st Edition
Max Hawthorne
https://ebookmeta.com/product/kronos-rising-purgatory-a-fast-paced-
sci-fi-suspense-thriller-book-6-in-the-kronos-rising-series-1st-
edition-max-hawthorne/
ebookmeta.com
Refactoring
Legacy T-SQL
for Improved
Performance
Modern Practices for SQL Server
Applications
—
Lisa Bohm
www.allitebooks.com
Refactoring Legacy T-SQL
for Improved Performance
Modern Practices for
SQL Server Applications
Lisa Bohm
www.allitebooks.com
Refactoring Legacy T-SQL for Improved Performance: Modern Practices for
SQL Server Applications
Lisa Bohm
Chardon, OH, USA
www.allitebooks.com
This book is dedicated to Allen White, who has been my friend as well as
helped me grow into a valued member of the community, and
taught me how important it is to keep giving back and
helping others.
www.allitebooks.com
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi
Introduction�����������������������������������������������������������������������������������������������������������xvii
Chapter 2: Documentation�������������������������������������������������������������������������������������� 21
Incorporating Existing Documentation���������������������������������������������������������������������������������������� 21
Functionality Documentation������������������������������������������������������������������������������������������������� 28
www.allitebooks.com
Table of Contents
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 233
ix
About the Author
Lisa Bohm leads a team of database administrators (DBAs)
for a software development company. Her history with
legacy database code began early in her career with a
summer project to rewrite the chemical inventory database
for the research division of a local VA hospital. From
there, she went on to building front-end web applications.
When the web calls timed out, Lisa dug in to learn what
databases can do. She has since transitioned into database
administration, inheriting and improving legacy applications
along the way. Her personal focus remains on solid database
architecture and writing well-performing T-SQL.
xi
About the Technical Reviewer
Kathi Kellenberger is a data platform MVP and the editor of Simple Talk at Redgate
Software. She has worked with SQL Server for over 20 years. She is also coleader of the
PASS Women in Technology Virtual Group and an instructor at LaunchCode. In her
spare time, Kathi enjoys spending time with family and friends, singing, and cycling.
xiii
Acknowledgments
I would like to thank all of the people who believed in me, encouraged, and pushed me
to continue to grow and learn. Special thanks go to Mindy Curnutt, Eric Blinn, and Tim
Tarbet, who showed me how amazing someone can be at the job they choose to do, and
believed that I could be that good too.
I cannot leave out the people who work for me. I lead a wonderful team of involved
people who are active in their continued learning, and continue to inspire me every day
by finding solutions to really difficult problems.
Also thank you to my family (including my #sqlfamily) who have always been
supportive, loving, and unstinting of hugs and moral support when needed!
xv
Introduction
What is legacy code? There are a few definitions floating around out there, but as a
working definition, we’re going to use the following:
Legacy code is code that is no longer being actively supported by the people who
wrote it.
Why are we going to use that? In software development, good documentation goes a
long way. Developers should understand what code is trying to accomplish and how it’s
trying to do so. When documentation either doesn’t exist or isn’t as thorough as required
and the original programmers aren’t available if you need to know why something was
written a particular way, it can be a nightmare to fix. In some cases, it may not even
be clear whether code ever worked as intended, or if the functionality of the change
someone is requesting is within the original intent of the programmer(s).
A Tale of Woe
How does legacy code start? Let’s look at this story. Code is written to solve a problem –
for example, someone is copying data into Excel every day and doing some hand
manipulation to generate a graph to add to a larger report. A developer sets up a quick
application to pull the data from the database and export it into Excel automatically for
the user, also performing the calculations the user was doing by hand.
This user then trains their successor and another person in the department on how
to view this report. One of them says, “Hey, this is great! Can you also make it pull data
for this other report and we can show how these numbers reflect against each other?”
Someone else loves the additional functionality but needs the code to work in a different
way, or do different statistical calculations, or needs to add an additional field on the
report. That person’s manager is intrigued by the functionality and wants a weekly
summary report to review. Code structure starts to resemble something that is cobbled
together, as multiple developers add bits of functionality over time. Oftentimes, there
is little to no documentation on the functionality or the choice of code – everyone just
adds a bunch of lines at the end of the code to handle the small part they were asked to
develop.
xvii
Introduction
Many times, front-end developers don’t specialize in T-SQL, so do not usually have
a deep understanding of the SQL Server optimizer. Especially in the case of “let’s just
add lines of code to the bottom of this to handle additional functionality,” calls to the
database can increase exponentially; in many cases, calls grab the same data over and
over. And, oh, by now, over half the company is using this app in one way or another – or
perhaps three ways. The vast majority of these uses, by the way, were never intended by
anyone who had ever touched the code.
Users complain about slowness and performance. Even more frustrating, all of the
other business-critical applications that use the same database(s) become slower and
slower as they fight for resources and locks with the application and its chatty data calls.
Also, of course, every developer that has ever touched this application has moved on or
has been promoted and hasn’t looked at code for years, so has no recollection of ever
manipulating any code even remotely similar to this patched-together behemoth that is
rampaging through the company infrastructure.
Congratulations!
You have inherited one of these types of applications, or you probably wouldn’t be
here reading this book. Although there will be (possibly many) times that you may
want to cry, yell, or swear, this will also give you some unparalleled opportunities to be
a hero and pull off some very spectacular-seeming fixes. Just remember, though, that
when you really fix something amazing, most people will be completely oblivious to
that fact. Then, when you do something you think is so obvious that a worm out there
on the sidewalk could probably manage it, you may get so many congratulations and
thanks that you’ll wonder if you really did something magical. That is probably more
of a general life/job observation and not related specifically to legacy code, but it’s also
prevalent here.
xviii
Introduction
We are going to continue on from the point of “Okay, this has been identified as an
issue. Now what do I do with it?” Most of what we’ll be doing is actually looking at the
code with the help of a few performance measures and learning about best practices to
help identify problem areas. You should be familiar with basic T-SQL coding syntax and
techniques and how to do a bit more advanced querying.
We will cover most of the issues commonly seen by object type, as well as a couple
of less common problems just for fun. Once these problem areas within the object are
identified, you can then mitigate the performance issues with relatively low effort and
cost. Some objects may require a much deeper dive. Once we’ve done some triage to
help alleviate the immediate pain an object is causing, we will cover what is involved in
effectively performing the deeper dive.
We also will talk about how to quickly tell if you’re on the right track in terms of the
fixes you want to apply. We’ll go over some simple (and free) tools that can be used to
measure performance, so you can document the before/after metrics to go along with
the rest of the documentation you’re going to be sure to add so the next poor sod
(I mean the next person) who has to maintain this system will have an easier time of it!
xix
Other documents randomly have
different content
The Project Gutenberg eBook of
Experimental glass blowing for boys
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Contributor: A. C. Gilbert
Language: English
FOR BOYS
BY
CARLETON J. LYNDE, Ph. D.
Professor of Physics
MacDonald College, Quebec Province, Canada
Boys, glass tubes are made in the sizes shown in Fig. 2, and in
larger sizes. You will use sizes 2, 4, and 6 in the following
experiments.
Experiment 1. Fun bending glass.
Hold a piece of No. 2, with both
hands, in the flame of the alcohol
lamp, and turn it constantly (Fig. 3).
Do you find that when the glass
becomes nearly red hot, it becomes FIG. 2
soft and bends easily?
SIZES OF GLASS TUBING
Take
the tube
out of the flame, bend it into any shape
you wish (Fig. 4), and allow it to cool.
Do you find that the glass hardens
when it cools and retains the bent
shape?
Heat the tube near the first bend,
turn it constantly, take it out of the
flame, and make another bend.
FIG. 3 Repeat this and make all kinds of
fantastic shapes.
HEATING GLASS TO Place all hot glass on the cooling
SOFTEN IT blocks, not on the table.
Glass is used in many, many ways by
the human race; for example, to make bottles, tumblers, window
glass, and so on, and all of these uses depend upon the facts which
you have just illustrated, namely, that glass becomes soft when
heated and hard when cooled again.
THE LAMP
The wick should be cut straight across and should project above
the wick holder about ⅛ inch (Fig. 5), or a little more if you require
more heat. Burn wood alcohol or grain alcohol, because they give
flames without soot or smoke. Fill the lamp to within a ½ inch of the
top only; it will burn one hour. The
hottest part of the flame is not down
close to the wick, as most beginners
suppose, but up just beneath the tip.
Buy
your
alcohol
at a drug
store in
FIG. 5 quantitie
s of one FIG. 4
THE LAMP pint or
more. BENDING GLASS
When
you are through experimenting for the
day pour the alcohol from the lamp back into the pint bottle and cork
the bottle tightly. Alcohol left in the lamp gradually evaporates and is
lost.
Do not let the lamp stand with alcohol in it for any considerable
time—overnight for example—because fuel alcohol contains water
and when it evaporates from the wick, the alcohol evaporates first
and leaves the water in the wick. Then when you try to light the wick
again, you will find that you cannot do so, because, of course, water
does not burn. If this happens to you, take the wick out, dry it, and
start the lamp again.
It is perfectly safe to use kerosene in
the lamp, but it gives a very smoky
flame which deposits soot on the glass
and fills the air with soot particles.
Your mother will object very
strenuously to this because the soot
particles settle and blacken everything.
Burn alcohol only, at least in the
house.
FIG. 6
MAKING A SCRATCH
FIG. 10
The “why” of it
FIG. 14
The “why” of it
You
boys
who
have the
Gilbert
set on
FIG. 15 “Hydraul
ic and
A BALLOON RACE Pneumat
ic
Engineering” will know the “why” of
the last three experiments. Any body FIG. 16
floats in water if it is lighter than an
equal volume of water, and it sinks if it DRAWING A THIN TUBE
is heavier than an equal volume of
water. Water is practically
incompressible but air is very compressible: thus when you press
down on the stopper, you force water into the balloon and compress
the air in it; when you release the stopper, the compressed air in the
balloon expands and drives the water out. When the weight of the
balloon and the weight of the water in it are together greater than the
weight of water displaced by the balloon, the balloon sinks; when
they are less, it rises.
Experiment 10. Fun with thin tubes.
Hold a piece of No. 2 tubing in the lamp flame and turn it
constantly. When it is red hot and soft, take it out of the flame
and pull your hands apart until the tube is stretched ten or twelve
inches (Fig. 16). Is the tube in the shape shown in Fig. 17?
FIG. 17
Allow the tube to cool, break the large ends away from the thin
tube, place one end of the thin tube in a glass of water, and blow into
the other end to make air bubbles in the water (Fig. 18). If you can do
so, it is a real tube.
Does the thin tube bend easily and
does it spring back when released?
Repeat the experiment with another
piece of No. 2 tubing, but make the
thin tube as long as you can.
Can you blow air through the thin
tube, and does it bend very easily
indeed?
Repeat with a piece of No. 4 tubing.
These thin hairlike tubes are called
“capillary” tubes, from the Latin word
capillus, meaning a hair.
FIG. 18
AIR THROUGH TUBE
WHAT IS GLASS?
Common glass is made from three substances with which you are
all more or less familiar; namely, sand, sodium carbonate (washing
soda), and lime.
If sand and soda or potash are mixed
and heated to a high temperature, they
melt together and produce a glass
which dissolves in water. This is
known as “water glass” and it is used in
many ways: to preserve eggs, to
cement fire bricks, to make fireproof
cement, and so on. If, however, lime is
added and the mixture is heated to a
high temperature, a glass is produced
which is not soluble in water. This is
the glass you know.
The three most common kinds of
glass are: Venetian glass, made from
sand, soda, and lime; Bohemian glass,
from sand, potash, and lime; and
crystal or flint glass, from sand,
potash, and lead oxide.
FIG. 20
WINDOW GLASS
Window glass is blown in exactly the same way as you have blown
glass balloons; the process is illustrated in Fig. 1.
The glass mixture is heated for about three days in fire clay pots
and is allowed to cool until it is viscous. The glass blower then
attaches a lump of the viscous glass to the end of a straight iron
blowpipe about five feet long and blows a bulb. He then reheats the
glass and blows a larger pear-shaped bulb and in doing so rests the
glass on a pear-shaped mold of charred wood (see center of Fig. 1).
He again reheats the glass, holds the pear-shaped bulb over a pit,
and blows a long cylinder (see left of Fig. 1).
The ends of the cylinder are now cut off and the edges are smeared
with molten glass to prevent splitting (see right, Fig. 21). The
cylinder is next cut lengthwise with a diamond (center, Fig. 21), and
is placed in a second hot oven, where it is ironed out flat (Fig. 22).
FIG. 23
The flat sheets are finally annealed in a third oven for a number of
days and are then cut into panes, sorted, and packed.
GLASS TUBES
FIG. 24
The glass tubes with which you do the experiments in this book are
made in the same way as window glass up to the stage of blowing the
cylinder; then the blower’s helper attaches an iron rod to the
opposite end of the cylinder (see right of Fig. 1), and the blower and
helper walk backward away from each other to pull the cylinder into
a tube. Of course, they use a small amount of glass to make small
tubes, and larger amounts for large tubes.
MOLDED GLASS
PRESSED GLASS
Many articles are made by pressing glass into molds, that is, the
molten glass is poured into molds and is pressed against the sides of
the mold by means of a plunger. Imitation cut glass is pressed in this
way.
PLATE GLASS
The large sheets of plate glass used in store windows are not
blown, but rolled. The molten glass is poured from the fire clay pots
upon a cast-iron table and is rolled flat by means of a large iron roller
(Fig. 24). The glass is then in the shape of plate glass, but is rough on
both sides. It is annealed for a number of days and then is ground
smooth on both sides, first with coarse emery, then with finer and
finer emery, and is finally polished with rouge. The result is the
beautifully polished plate glass we see in large windows.
OPTICAL GLASS
The United States and Great Britain made great strides in the
manufacture of optical glass during the war and there are now many
kinds on the market. They are used in making the lenses, prisms, and
mirrors for optical instruments.
Optical glass is made in much the same way as ordinary glass, but
great care is taken: first, to see that the materials are pure; second, to
stir the glass constantly, as it cools from the molten to the viscous
state, to make it as uniform as possible; and third, to cool it very
slowly in the annealing process, to avoid strains.
QUARTZ GLASS
An entirely new glass has been
placed on the market in quantity in
recent years. It is made by melting very
pure quartz sand at a temperature of
3000° F. and cooling it fairly rapidly.
It has the very valuable property of
expanding and contracting very, very
slightly when heated and cooled. Thus
there is practically no internal strain
set up when it is heated or cooled
quickly and it does not break. It can be
heated red hot, for example, and then
plunged into cold water without
breaking. It is probable that this glass
will be in universal use in a very few
years.
FIG. 25
A POLLYWOG
Experiment 12. To make an acrobatic
pollywog.
Smooth one end of a piece of No. 2 tube to put in your mouth,
close the other end in the blowpipe flame, take it out and blow a bulb
about ½ inch in diameter.
Allow the bulb to cool, then heat the tube about ¼ inch from the
bulb and draw it out into a thin tube. Now bend the thin tube at right
angles near the bulb and break it off (Fig. 25).
Place the bulb in water. Does it float? If not, blow another with a
larger bulb.
Experiment 13. Magic.
Place the pollywog in a bottle filled
to overflowing with water, insert the
solid rubber stopper, and press it down
hard. Does the pollywog sink?
Now release the stopper quickly.
Does the pollywog turn somersaults in
a most magical manner (1, Fig. 26),
and also rise?
FIG. 26
Make one or two more pollywogs,
ACROBATS place them all in the bottle together (2,
Fig. 26), and entertain your friends
with a pollywog circus.
The pollywog sinks when you press down on the stopper because
you compress the air in it and force water in until it weighs more
than the water it displaces.
The pollywog rises when you release
the stopper because the compressed
air drives the water out until the
pollywog weighs less than the water it
displaces.
The pollywog turns a somersault
because the water rushes out sidewise
in one direction and forces the nozzle
in the other direction.
Air may escape from the pollywog FIG. 27
when it is turning a somersault; if so,
water will take its place, and may make DANCING POLLYWOGS
the pollywog too heavy to float. You
can restore its buoyancy by sucking out
the water.