100% found this document useful (2 votes)
24 views

Instant Download Refactoring Legacy T-SQL for Improved Performance 1st Edition Lisa Bohm PDF All Chapters

Improved

Uploaded by

dalamamaanni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
24 views

Instant Download Refactoring Legacy T-SQL for Improved Performance 1st Edition Lisa Bohm PDF All Chapters

Improved

Uploaded by

dalamamaanni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Get ebook downloads in full at ebookmeta.

com

Refactoring Legacy T-SQL for Improved Performance


1st Edition Lisa Bohm

https://ebookmeta.com/product/refactoring-legacy-t-sql-for-
improved-performance-1st-edition-lisa-bohm/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Smart Technologies for Improved Performance of


Manufacturing Systems and Services 1st Edition Bikash
Chandra Behera
https://ebookmeta.com/product/smart-technologies-for-improved-
performance-of-manufacturing-systems-and-services-1st-edition-bikash-
chandra-behera/
ebookmeta.com

Pro T-SQL 2019: Toward Speed, Scalability, and


Standardization for SQL Server Developers 1st Edition
Elizabeth Noble
https://ebookmeta.com/product/pro-t-sql-2019-toward-speed-scalability-
and-standardization-for-sql-server-developers-1st-edition-elizabeth-
noble/
ebookmeta.com

Legacy The Netherworld Academy 1 1st Edition Lisa Cardwell

https://ebookmeta.com/product/legacy-the-netherworld-academy-1-1st-
edition-lisa-cardwell/

ebookmeta.com

On Middle Ground A History of the Jews of Baltimore Eric


L. Goldstein

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

Languaging Diversity Volume 3 Language s and Power 1st


Edition Elena Di Giovanni

https://ebookmeta.com/product/languaging-diversity-volume-3-language-
s-and-power-1st-edition-elena-di-giovanni/

ebookmeta.com

The Social Life of Hagiography in the Merovingian Kingdom


Kreiner

https://ebookmeta.com/product/the-social-life-of-hagiography-in-the-
merovingian-kingdom-kreiner/

ebookmeta.com

The School of Hillah and the Formation of Twelver Shi i


Islamic Tradition 1st Edition Aun Hasan Ali

https://ebookmeta.com/product/the-school-of-hillah-and-the-formation-
of-twelver-shi-i-islamic-tradition-1st-edition-aun-hasan-ali/

ebookmeta.com

Savannah Mafia 1 Cruel Prince 1st Edition M A Lee

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

ISBN-13 (pbk): 978-1-4842-5580-3 ISBN-13 (electronic): 978-1-4842-5581-0


https://doi.org/10.1007/978-1-4842-5581-0

Copyright © 2020 by Lisa Bohm


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Jonathan Gennick
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com,
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is
Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484255803. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper

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

About the Technical Reviewer������������������������������������������������������������������������������� xiii


Acknowledgments���������������������������������������������������������������������������������������������������xv

Introduction�����������������������������������������������������������������������������������������������������������xvii

Part I: Everything Is Slow������������������������������������������������������������������������������� 1


Chapter 1: T-SQL Triage�������������������������������������������������������������������������������������������� 3
Severity of the Situation���������������������������������������������������������������������������������������������������������������� 4
Relative Effort������������������������������������������������������������������������������������������������������������������������������� 4
Problem Areas������������������������������������������������������������������������������������������������������������������������������� 4
STATISTICS IO and Time����������������������������������������������������������������������������������������������������������� 5
Query Window Setup��������������������������������������������������������������������������������������������������������������� 5
Code Tests������������������������������������������������������������������������������������������������������������������������������� 6
Execution Plans��������������������������������������������������������������������������������������������������������������������� 11
Perform Triage if Possible����������������������������������������������������������������������������������������������������������� 14
Is There an Index?����������������������������������������������������������������������������������������������������������������� 14
Risk Level of the Change������������������������������������������������������������������������������������������������������� 17
The Answer to Everything…?����������������������������������������������������������������������������������������������������� 18
Triage Outside of Indexing���������������������������������������������������������������������������������������������������������� 18
If Possible, Queries Should Join on Key Values��������������������������������������������������������������������� 19
SARGability���������������������������������������������������������������������������������������������������������������������������� 19
Summary������������������������������������������������������������������������������������������������������������������������������������ 19

Chapter 2: Documentation�������������������������������������������������������������������������������������� 21
Incorporating Existing Documentation���������������������������������������������������������������������������������������� 21
Functionality Documentation������������������������������������������������������������������������������������������������� 28

www.allitebooks.com
Table of Contents

Statistics Information and Execution Plans�������������������������������������������������������������������������������� 29


Coding (Anti) Patterns����������������������������������������������������������������������������������������������������������������� 29
Number of Calls to Each Database Table������������������������������������������������������������������������������� 30
Datatype Mismatches������������������������������������������������������������������������������������������������������������ 31
Subqueries and Where They’re Located�������������������������������������������������������������������������������� 38
Calculations��������������������������������������������������������������������������������������������������������������������������� 38
Temporary Tables and/or Table Variables������������������������������������������������������������������������������ 40
Loops and/or Cursors������������������������������������������������������������������������������������������������������������ 41
CTEs��������������������������������������������������������������������������������������������������������������������������������������� 42
Join Types������������������������������������������������������������������������������������������������������������������������������ 42
LIKE, NOT LIKE, and NOT IN���������������������������������������������������������������������������������������������������� 43
DISTINCT, TOP, and Other Sorting Operations������������������������������������������������������������������������� 43
Calls to Other User-Defined SQL Objects������������������������������������������������������������������������������� 44
Native SQL Server Functions in a WHERE Clause������������������������������������������������������������������ 44
Indexes���������������������������������������������������������������������������������������������������������������������������������������� 48
Back to Runtime Data������������������������������������������������������������������������������������������������������������ 48
Summary������������������������������������������������������������������������������������������������������������������������������������ 48
Wrapping Up Our Documentation������������������������������������������������������������������������������������������ 48
DailySummaryReportPerMonth: Documentation������������������������������������������������������������������������� 48
Code as of 2019.06.02����������������������������������������������������������������������������������������������������������� 48
Functional Requirements������������������������������������������������������������������������������������������������������ 56
Data Calls������������������������������������������������������������������������������������������������������������������������������ 56
Coding (Anti) Patterns������������������������������������������������������������������������������������������������������������ 57
Indexes���������������������������������������������������������������������������������������������������������������������������������� 59

Part II: Database Structure��������������������������������������������������������������������������� 61


Chapter 3: Database Tables������������������������������������������������������������������������������������ 63
Computed Columns��������������������������������������������������������������������������������������������������������������������� 63
Denormalized Data���������������������������������������������������������������������������������������������������������������������� 63
Datatypes and Field Size������������������������������������������������������������������������������������������������������������� 65
Deprecated Datatypes����������������������������������������������������������������������������������������������������������������� 66

vi
Table of Contents

How Much Data?������������������������������������������������������������������������������������������������������������������������� 66


Data Skew/Cardinality���������������������������������������������������������������������������������������������������������������� 67
Constraints���������������������������������������������������������������������������������������������������������������������������������� 68
Changing Table Definitions���������������������������������������������������������������������������������������������������������� 69
Summary������������������������������������������������������������������������������������������������������������������������������������ 82

Chapter 4: Database Views������������������������������������������������������������������������������������� 83


Nesting���������������������������������������������������������������������������������������������������������������������������������������� 84
Multiple Table Calls���������������������������������������������������������������������������������������������������������������� 95
Additional Pieces for Documentation������������������������������������������������������������������������������������ 97
Know Your Data��������������������������������������������������������������������������������������������������������������������� 97
Functionality Check��������������������������������������������������������������������������������������������������������������������� 99
What Problems Did We Fix?������������������������������������������������������������������������������������������������������ 103
Filtering������������������������������������������������������������������������������������������������������������������������������������� 104
Updating Data Through a View�������������������������������������������������������������������������������������������������� 104
Additional Limitations��������������������������������������������������������������������������������������������������������������� 105
Why Use a View?����������������������������������������������������������������������������������������������������������������������� 105
Summary���������������������������������������������������������������������������������������������������������������������������������� 105

Part III: CRUD Objects��������������������������������������������������������������������������������� 107


Chapter 5: Triggers����������������������������������������������������������������������������������������������� 109
View-Based Triggers����������������������������������������������������������������������������������������������������������������� 109
When Should We Use Triggers?������������������������������������������������������������������������������������������������ 110
Common Issues with Triggers��������������������������������������������������������������������������������������������������� 110
Trigger Recursion���������������������������������������������������������������������������������������������������������������������� 114
Triggers and Multi-record Changes������������������������������������������������������������������������������������������ 119
Testing for Values Changing������������������������������������������������������������������������������������������������������ 123
Limit the Work Your Database Must Do������������������������������������������������������������������������������������� 129
Summary���������������������������������������������������������������������������������������������������������������������������������� 135

vii
Table of Contents

Chapter 6: Stored Procedures������������������������������������������������������������������������������ 137


Temporary Tables vs. Table Variables���������������������������������������������������������������������������������������� 137
The Temporary Table����������������������������������������������������������������������������������������������������������� 138
The Table Variable���������������������������������������������������������������������������������������������������������������� 138
Loops���������������������������������������������������������������������������������������������������������������������������������������� 139
Functionality Review����������������������������������������������������������������������������������������������������������������� 139
Start with the Simplest Data����������������������������������������������������������������������������������������������������� 139
Add More Data in Small, Easily Testable Increments����������������������������������������������������������� 142
Windowing Functions���������������������������������������������������������������������������������������������������������������� 144
Avoiding Row or Data Duplicates���������������������������������������������������������������������������������������������� 146
How Did We Get Here Again?���������������������������������������������������������������������������������������������������� 151
But What About Performance?�������������������������������������������������������������������������������������������������� 153
No Missing Rows – Tally Tables!����������������������������������������������������������������������������������������������� 171
What Else Should We Watch For?��������������������������������������������������������������������������������������������� 177
GetUserInfoByName: Documentation���������������������������������������������������������������������������������������� 177
Code as of 2019.07.07��������������������������������������������������������������������������������������������������������� 177
Functional Requirements���������������������������������������������������������������������������������������������������� 179
Data Calls���������������������������������������������������������������������������������������������������������������������������� 179
Possible Red Flags�������������������������������������������������������������������������������������������������������������� 180
Run Statistics for This Call�������������������������������������������������������������������������������������������������������� 181
Functions and STATISTICS IO Output����������������������������������������������������������������������������������������� 182
Coming Up with a Plan of Action����������������������������������������������������������������������������������������������� 183
Go Away, Subqueries!���������������������������������������������������������������������������������������������������������� 183
Remove the Function!��������������������������������������������������������������������������������������������������������� 185
Remove the Leading % in Our LIKE Statement�������������������������������������������������������������������� 186
Summary���������������������������������������������������������������������������������������������������������������������������������� 190

Chapter 7: Functions�������������������������������������������������������������������������������������������� 191


Scalar Functions����������������������������������������������������������������������������������������������������������������������� 191
Viewing STATISTICS IO Caused by Functions���������������������������������������������������������������������������� 193
Scalar-Valued Functions in a WHERE Clause���������������������������������������������������������������������������� 199

viii
Table of Contents

Native SQL Server Functions���������������������������������������������������������������������������������������������������� 200


The Dreaded “Massive Business Logic” Function�������������������������������������������������������������������� 203
Using OUTER APPLY to Join Aggregate Data����������������������������������������������������������������������������� 211
Metrics with Increasing Number of Return Rows���������������������������������������������������������������� 213
Table Valued Functions (TVFs)��������������������������������������������������������������������������������������������������� 215
Summary���������������������������������������������������������������������������������������������������������������������������������� 218

Part IV: The Bad and the Ugly��������������������������������������������������������������������� 219


Chapter 8: Agent Jobs������������������������������������������������������������������������������������������ 221
What Agent Jobs Should Be Doing�������������������������������������������������������������������������������������������� 221
Good Job(s)!������������������������������������������������������������������������������������������������������������������������ 221
When Should I Run Jobs?���������������������������������������������������������������������������������������������������� 222
Common Issues with Agent Jobs���������������������������������������������������������������������������������������������� 224
Overlap�������������������������������������������������������������������������������������������������������������������������������� 224
Summary���������������������������������������������������������������������������������������������������������������������������������� 226

Chapter 9: External Influences����������������������������������������������������������������������������� 227


Linked Servers�������������������������������������������������������������������������������������������������������������������������� 227
Security������������������������������������������������������������������������������������������������������������������������������� 227
Queries Joining Tables from Different Databases��������������������������������������������������������������� 228
Network IO��������������������������������������������������������������������������������������������������������������������������� 228
How Can We Fix This?��������������������������������������������������������������������������������������������������������� 229
SQL Code Calls in the Application��������������������������������������������������������������������������������������������� 229
So What’s the Problem?������������������������������������������������������������������������������������������������������ 229
Dynamic SQL����������������������������������������������������������������������������������������������������������������������� 231
Summary���������������������������������������������������������������������������������������������������������������������������������� 231

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.

What This Book Is


This book is meant to help you, the reader, step in and identify potential issues in a
specific database object relatively quickly. There are a few assumptions that go with this:

1. Hardware/hardware configuration/VM configuration has been


ruled out as the performance problem.

xviii
Introduction

2. External sources have been ruled out as the problem (although we


all know it’s really the network…).

3. The database objects that are causing concern have been


identified.

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!

What This Book Is Not


Magic. This book is not magic, although at times it might seem like it helps you perform
some. Seriously though, there are times when things are so bad that you cannot fix them.
This is pretty rare, and either myself or one of the members of my various teams has
almost always managed to “just fix it,” but just be aware that it is possible that something
is unsalvageable. Even better, your boss should also be aware of this and have your back
should you run into that situation. If you are not that fortunate, you may want to consider
finding another job, but that is probably outside the scope of this book.

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.

Title: Experimental glass blowing for boys

Author: Carleton John Lynde

Contributor: A. C. Gilbert

Release date: June 16, 2024 [eBook #73841]

Language: English

Original publication: New Haven: The A. C. Gilbert Company,


1920

Credits: Richard Tonsing, deaurider, and the Online Distributed


Proofreading Team at https://www.pgdp.net (This file
was produced from images generously made available
by The Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK EXPERIMENTAL


GLASS BLOWING FOR BOYS ***
Transcriber’s Note:
New original cover art included with this eBook is
granted to the public domain.
Experimental Glass Blowing

FOR BOYS

BY
CARLETON J. LYNDE, Ph. D.
Professor of Physics
MacDonald College, Quebec Province, Canada

Prepared under the direction of


ALFRED C. GILBERT
Yale University, 1909
EXPERIMENTAL GLASS BLOWING

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

Experiment 2. To cut glass tubing.


Cut off a six-inch length of No. 2 as
follows: Lay the tube flat on the table,
mark the six-inch length and draw the
file across the tube at this point,
FIG. 7 pressing hard enough to make a good
scratch (Fig. 6). Grasp the tube with
BREAKING THE TUBE both hands near the scratch, as in Fig.
7, pull apart and bend slightly. Do you
find that the tube breaks across easily?
Repeat this with No. 4 and No. 6 tubes.
Experiment 3. To make the edges smooth.
Hold one end of the six-inch piece of
No. 2 in the tip of the flame (Fig. 8),
and turn constantly until it is just red
hot. Take it out and let it cool on the
blocks. Do you find that the edges are
smooth?
Repeat with the other end.
Repeat with both ends of the six-
inch piece of No. 4.
If thick glass is heated quickly it may
crack, because the hot exterior FIG. 8
expands more quickly than the cooler
interior and produces internal strains. MAKING THE EDGES
The SMOOTH
No. 6
tube is
comparatively thick and should be
heated gradually as follows: Hold the
end in the flame for about 1 second,
then withdraw it for about 1 second;
hold it in the flame again for 1 second,
and withdraw it for 1 second. Repeat
this eight or ten times, then hold and
turn it in the flame until red hot.
FIG. 9 Smooth both ends of the No. 6 piece
in this way.
THE BLOWPIPE FLAME
Experiment 4. Practice with the blowpipe.
Hold the small end of the blowpipe just inside the flame at one
edge, about ⅛ inch above the wick (Fig. 9), and blow air through the
flame parallel to the top of the wick.
Keep your mouth closed on the blowpipe, breathe through your
nose, and practice keeping a steady stream of air going for a
long time. You will be able to do this with a little practice.
Do you observe that the blowpipe flame is pointed, also that it is
made up of a pointed cone inside and a lighter-colored cone outside?
The hottest part of the flame is inside the outer cone just beyond the
point of the inner cone.
The blowpipe flame is hotter than
the lamp flame because the heat of the
burning alcohol is concentrated at one
point by means of the air blast, and
because the alcohol is more completely
burned by the extra air.

FIG. 10

CLOSING ONE END OF A


TUBE
Experiment 5. To close the end of a small
tube.
Hold one end of a piece of No. 2 tube in the blowpipe flame (Fig.
10), turn it slowly, and heat until the end closes. Does it close nicely?
Close one end of a piece of No. 4 in the same way.
You can close No. 6 tubing in this way, but it leaves a large lump of
glass which may crack on cooling or on reheating. You will practice
closing No. 6 tubing later.

The “why” of it

The glass becomes soft when heated because it becomes almost a


liquid, and if it is heated sufficiently it becomes entirely a liquid. In
this respect it acts very much as pitch, rosin, and wax act when
heated by the sun or by a fire.
The end of a glass tube becomes
smooth, or closes entirely, when
heated, for the following reason: The
surface of any liquid tries to take the
smallest possible area (this is
explained in detail under “Surface
Tension” in the Gilbert book on
“Experimental Mechanics”), for
example, a small particle of water takes
the shape of a drop, a sphere, and the
surface of a sphere has the least area
for a given amount of water. Now
FIG. 11 when the end of the glass tube is
heated it becomes a liquid, and the
MAKING A GLASS surface of this liquid contracts the
BUBBLE glass into a smooth rounded surface of
least area. If the tube is heated still
more, the surface contracts still more and closes the end.
Experiment 6. Fun blowing glass bubbles.
Smooth one end of a piece of No. 2 tube and allow it to cool. Close
the other end in the blowpipe flame, turn it slowly, and heat until it is
very hot. Take the tube out of the flame, put the smooth end into
your mouth quickly, and blow as hard as you can (Fig. 11). Do you get
a fine big glass bubble which bursts with a pop?
If you get only a small bulb at the first trial, heat the end, and try
again. Do you find that the bulb shrinks when heated but blows out
again readily?
When you get a big bubble, place the
bubble end of the tube on a cooling
block and break all the thin glass away
from the tube by striking it with the file
or blowpipe. Then close the end and
blow another bubble.
Repeat until you can blow bubbles
easily.
Repeat with a piece of No. 4 tube.

BUBBLE COLORS FIG. 12

Do you find that the thin glass of the BLOWING A BULB


bubbles shows colors, especially in
sunlight, just as soap bubbles do? You
boys who have had the Gilbert set on “Light Experiments” will know
that these colors are due to “interference.” The colors produced by a
thin film of oil on water are also produced by “interference.”
Experiment 7. To make
water balloons.
Close one end of the No. 2 tube in
the blowpipe flame again and while it
is still hot blow carefully into the open
end until you have a bulb about ½ inch
in diameter (Fig. 12). Now let it cool.
Make a scratch with the file about ¼
inch from the bulb, break the tube at
this point (Fig. 13), and smooth the
rough edge.
Put the bulb in a tumbler of water.
FIG. 13 Does it float? If not, make another
balloon with a larger bulb.
A WATER BALLOON
Experiment 8. Magic.
Find a large bottle made of clear
glass, the neck of which will fit your
solid rubber stopper.
Fill the bottle with water to
overflowing, insert the balloon, and
then the stopper.
Now press down hard on the
stopper. Does the balloon sink in a
most magical manner (Fig. 14)?
Release the stopper. Does the
balloon rise in an equally magical
manner?

FIG. 14

THE BALLOON SINKS


AND RISES
Experiment 9. Balloon
races.
Make another water balloon. Put the
two balloons together in the bottle
filled to overflowing with water.
Insert the stopper and press down
hard. Do the balloons sink (Fig. 15),
and does one sink more quickly than
the other?
Release the stopper. Do the balloons
rise, and does one rise more quickly
than the other?
The most buoyant balloon sinks last
and rises first.

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

A GLASS TUBE STRETCHED

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

Experiment 11. Magic.


You have always heard that water
runs downhill, but you will now see it
run uphill and remain there in a most
magical manner.
Cut off 5-inch lengths of No. 6, No.
4, and No. 2 tubing, stand them side by
side in a glass full of water (Fig. 19),
and move them up and down in the
water to wet the inside of the tubes.
Now look at the water level in each FIG. 19
of the tubes. Is it above the level of the
water in the glass, and is it higher the WATER RUNS UPHILL
smaller the inside diameter of the tube,
that is, is it higher in the No. 2 than in
No. 4, and in No. 4 than in No. 6?
Now take the thin capillary tube which has the largest inside
diameter, place one end in the glass of water, suck it full of water and
blow it out. Now with one end in the glass of water notice quickly
how the water rises inside the tube. Does it run uphill in a most
magical manner (Fig. 20), and does it remain there?
Repeat this with your other capillary tubes. Does the water run
uphill in each, and does it rise higher the smaller the inside diameter
of the tube?
The “why” of this is explained in Gilbert’s “Experimental
Mechanics” under “Capillarity.”

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

WATER RUNS UP TUBE


FIG. 21

SECOND STEP IN MAKING WINDOW PANES


FIG. 22

IRONING THE CYLINDERS FLAT

HOW ARE THINGS MADE OF GLASS?

The glass mixture is heated to a high temperature in fire clay pots


or tanks in large ovens. The surface is skimmed from time to time
and the heating is continued until all air bubbles have escaped from
the mixture, usually about three days.
The glass is now quite fluid and it is allowed to cool somewhat
until it is viscous; then the objects are made by blowing, pressing, or
rolling, as described below.
The finished articles are finally “annealed,” that is, they are placed
while still hot in a second hot oven, which is then sealed and allowed
to cool slowly, for four or five days or for as many weeks, according
to the kind of glass.
If a glass object cools quickly, it cools more rapidly on the surface
than in the interior. This produces a condition of strain in the glass
and the object may drop to pieces when jarred or scratched. This
condition of strain is avoided by allowing the objects to cool very
slowly, that is, by annealing.

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

BOTTLES BLOWN IN A MOLD

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

ROLLING PLATE GLASS

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

Many articles of glass are made by blowing the glass in molds.


Bottles are made in this way (Fig. 23), and large machines are now in
use which mold many bottles at one time in this way.

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.

You might also like