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

Complete Download SQL Performance Explained Markus Winand PDF All Chapters

The document provides information about the ebook 'SQL Performance Explained' by Markus Winand, which covers essential concepts for developers regarding SQL performance, particularly focusing on indexing. It includes a detailed table of contents outlining various chapters that discuss topics such as the anatomy of an index, performance and scalability, join operations, and modifying data. Additionally, it emphasizes the importance of understanding indexing for optimizing SQL queries and provides links to download the ebook and related resources.

Uploaded by

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

Complete Download SQL Performance Explained Markus Winand PDF All Chapters

The document provides information about the ebook 'SQL Performance Explained' by Markus Winand, which covers essential concepts for developers regarding SQL performance, particularly focusing on indexing. It includes a detailed table of contents outlining various chapters that discuss topics such as the anatomy of an index, performance and scalability, join operations, and modifying data. Additionally, it emphasizes the importance of understanding indexing for optimizing SQL queries and provides links to download the ebook and related resources.

Uploaded by

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

Visit https://ebookultra.

com to download the full version and


explore more ebooks

SQL Performance Explained Markus Winand

_____ Click the link below to download _____


https://ebookultra.com/download/sql-performance-
explained-markus-winand/

Explore and download more ebooks at ebookultra.com


Here are some suggested products you might be interested in.
Click the link to download

Building Performance Dashboards and Balanced Scorecards


with SQL Server Reporting Services 1st Edition Knight

https://ebookultra.com/download/building-performance-dashboards-and-
balanced-scorecards-with-sql-server-reporting-services-1st-edition-
knight/

Modern Fortran in Practice Markus

https://ebookultra.com/download/modern-fortran-in-practice-markus/

SQL Server T SQL Recipes 4th Edition Jason Brimhall

https://ebookultra.com/download/sql-server-t-sql-recipes-4th-edition-
jason-brimhall/

Microsoft SQL Server 2012 T SQL 1st Edition Tom Coffing

https://ebookultra.com/download/microsoft-sql-server-2012-t-sql-1st-
edition-tom-coffing/
European Democracies 9th Edition Markus M.L. Crepaz

https://ebookultra.com/download/european-democracies-9th-edition-
markus-m-l-crepaz/

Modernizing Enterprise Java 1st Edition Markus Eisele

https://ebookultra.com/download/modernizing-enterprise-java-1st-
edition-markus-eisele/

Essential SQL on SQL Server 2008 1st Edition Dr. Sikha


Bagui

https://ebookultra.com/download/essential-sql-on-sql-server-2008-1st-
edition-dr-sikha-bagui/

Myths Legends Explained Neil Philip

https://ebookultra.com/download/myths-legends-explained-neil-philip/

Joe Celko s SQL for Smarties Fourth Edition Advanced SQL


Programming Joe Celko

https://ebookultra.com/download/joe-celko-s-sql-for-smarties-fourth-
edition-advanced-sql-programming-joe-celko/
SQL Performance Explained Markus Winand Digital
Instant Download
Author(s): Markus Winand
ISBN(s): 9783950307825, 3950307826
Edition: Paperback
File Details: PDF, 1.17 MB
Year: 2012
Language: english
MA CO
JOR VER
SQ S A
L D LL
ATA
BA

SQL SES

PERFORMANCE
EXPLAINED
ENGLISH EDITION

EVERYTHING DEVELOPERS NEED TO KNOW ABOUT SQL PERFORMANCE

MARKUS WINAND
License Agreement
This ebook is licensed for your personal enjoyment only. This ebook may
not be re-sold or given away to other people. If you would like to share
this book with another person, please purchase an additional copy for each
person. If you’re reading this book and did not purchase it, or it was not
purchased for your use only, then please return to
http://SQL-Performance-Explained.com/
and purchase your own copy. Thank you for respecting the hard work of
the author.
Publisher:
Markus Winand

Maderspergerstasse 1-3/9/11
1160 Wien
AUSTRIA
<[email protected]>

Copyright © 2012 Markus Winand

All rights reserved. No part of this publication may be reproduced, stored,


or transmitted in any form or by any means —electronic, mechanical,
photocopying, recording, or otherwise — without the prior consent of the
publisher.

Many of the names used by manufacturers and sellers to distinguish their


products are trademarked. Wherever such designations appear in this book,
and we were aware of a trademark claim, the names have been printed in
all caps or initial caps.

While every precaution has been taken in the preparation of this book, the
publisher and author assume no responsibility for errors and omissions, or
for damages resulting from the use of the information contained herein.

The book solely reflects the author’s views. The database vendors men-
tioned have neither supported the work financially nor verified the content.

DGS - Druck- u. Graphikservice GmbH — Wien — Austria

Cover design:
tomasio.design — Mag. Thomas Weninger — Wien — Austria

Cover photo:
Brian Arnold — Turriff — UK

Copy editor:
Nathan Ingvalson — Graz — Austria

2014-08-26
SQL Performance Explained

Everything developers need to


know about SQL performance

Markus Winand
Vienna, Austria
Contents
Preface ............................................................................................ vi

1. Anatomy of an Index ...................................................................... 1


The Index Leaf Nodes .................................................................. 2
The Search Tree (B-Tree) .............................................................. 4
Slow Indexes, Part I .................................................................... 6

2. The Where Clause ......................................................................... 9


The Equality Operator .................................................................. 9
Primary Keys ....................................................................... 10
Concatenated Indexes .......................................................... 12
Slow Indexes, Part II ............................................................ 18
Functions .................................................................................. 24
Case-Insensitive Search Using UPPER or LOWER .......................... 24
User-Defined Functions ........................................................ 29
Over-Indexing ...................................................................... 31
Parameterized Queries ............................................................... 32
Searching for Ranges ................................................................. 39
Greater, Less and BETWEEN ..................................................... 39
Indexing LIKE Filters ............................................................. 45
Index Merge ........................................................................ 49
Partial Indexes ........................................................................... 51
NULL in the Oracle Database ....................................................... 53
Indexing NULL ....................................................................... 54
NOT NULL Constraints ............................................................ 56
Emulating Partial Indexes ..................................................... 60
Obfuscated Conditions ............................................................... 62
Date Types .......................................................................... 62
Numeric Strings .................................................................. 68
Combining Columns ............................................................ 70
Smart Logic ......................................................................... 72
Math .................................................................................. 77

iv
SQL Performance Explained

3. Performance and Scalability ......................................................... 79


Performance Impacts of Data Volume ......................................... 80
Performance Impacts of System Load .......................................... 85
Response Time and Throughput ................................................. 87

4. The Join Operation ....................................................................... 91


Nested Loops ............................................................................ 92
Hash Join ................................................................................. 101
Sort Merge .............................................................................. 109

5. Clustering Data ........................................................................... 111


Index Filter Predicates Used Intentionally ................................... 112
Index-Only Scan ........................................................................ 116
Index-Organized Tables ............................................................. 122

6. Sorting and Grouping ................................................................. 129


Indexing Order By .................................................................... 130
Indexing ASC, DESC and NULLS FIRST/LAST ...................................... 134
Indexing Group By .................................................................... 139

7. Partial Results ............................................................................ 143


Querying Top-N Rows ............................................................... 143
Paging Through Results ............................................................ 147
Using Window Functions for Pagination .................................... 156

8. Modifying Data .......................................................................... 159


Insert ...................................................................................... 159
Delete ...................................................................................... 162
Update .................................................................................... 163

A. Execution Plans .......................................................................... 165


Oracle Database ....................................................................... 166
PostgreSQL ............................................................................... 172
SQL Server ............................................................................... 180
MySQL ..................................................................................... 188

Index ............................................................................................. 193

v
Preface

Developers Need to Index


SQL performance problems are as old as SQL itself— some might even say
that SQL is inherently slow. Although this might have been true in the early
days of SQL, it is definitely not true anymore. Nevertheless SQL performance
problems are still commonplace. How does this happen?

The SQL language is perhaps the most successful fourth-generation


programming language (4GL). Its main benefit is the capability to separate
“what” and “how”. An SQL statement is a straight description what is needed
without instructions as to how to get it done. Consider the following
example:

SELECT date_of_birth
FROM employees
WHERE last_name = 'WINAND'

The SQL query reads like an English sentence that explains the requested
data. Writing SQL statements generally does not require any knowledge
about inner workings of the database or the storage system (such as disks,
files, etc.). There is no need to tell the database which files to open or how
to find the requested rows. Many developers have years of SQL experience
yet they know very little about the processing that happens in the database.

The separation of concerns — what is needed versus how to get it — works


remarkably well in SQL, but it is still not perfect. The abstraction reaches
its limits when it comes to performance: the author of an SQL statement
by definition does not care how the database executes the statement.
Consequently, the author is not responsible for slow execution. However,
experience proves the opposite; i.e., the author must know a little bit about
the database to prevent performance problems.

It turns out that the only thing developers need to learn is how to index.
Database indexing is, in fact, a development task. That is because the
most important information for proper indexing is not the storage system
configuration or the hardware setup. The most important information for
indexing is how the application queries the data. This knowledge —about

vi
Preface: Developers Need to Index

the access path— is not very accessible to database administrators (DBAs) or


external consultants. Quite some time is needed to gather this information
through reverse engineering of the application: development, on the other
hand, has that information anyway.

This book covers everything developers need to know about indexes — and
nothing more. To be more precise, the book covers the most important
index type only: the B-tree index.

The B-tree index works almost identically in many databases. The book only
uses the terminology of the Oracle® database, but the principles apply to
other databases as well. Side notes provide relevant information for MySQL,
PostgreSQL and SQL Server®.

The structure of the book is tailor-made for developers; most chapters


correspond to a particular part of an SQL statement.

CHAPTER 1 - Anatomy of an Index


The first chapter is the only one that doesn’t cover SQL specifically; it
is about the fundamental structure of an index. An understanding of
the index structure is essential to following the later chapters — don’t
skip this!

Although the chapter is rather short —only about eight pages —


after working through the chapter you will already understand the
phenomenon of slow indexes.

CHAPTER 2 - The Where Clause


This is where we pull out all the stops. This chapter explains all aspects
of the where clause, from very simple single column lookups to complex
clauses for ranges and special cases such as LIKE.

This chapter makes up the main body of the book. Once you learn to
use these techniques, you will write much faster SQL.

CHAPTER 3 - Performance and Scalability


This chapter is a little digression about performance measurements
and database scalability. See why adding hardware is not the best
solution to slow queries.

CHAPTER 4 - The Join Operation


Back to SQL: here you will find an explanation of how to use indexes
to perform a fast table join.

vii
Preface: Developers Need to Index

CHAPTER 5 - Clustering Data


Have you ever wondered if there is any difference between selecting a
single column or all columns? Here is the answer —along with a trick
to get even better performance.

CHAPTER 6 - Sorting and Grouping


Even order by and group by can use indexes.

CHAPTER 7 - Partial Results


This chapter explains how to benefit from a “pipelined” execution if
you don’t need the full result set.

CHAPTER 8 - Insert, Delete and Update


How do indexes affect write performance? Indexes don’t come for
free — use them wisely!

APPENDIX A - Execution Plans


Asking the database how it executes a statement.

viii
Chapter 1

Anatomy of an Index

“An index makes the query fast” is the most basic explanation of an index I
have ever seen. Although it describes the most important aspect of an index
very well, it is —unfortunately—not sufficient for this book. This chapter
describes the index structure in a less superficial way but doesn’t dive too
deeply into details. It provides just enough insight for one to understand
the SQL performance aspects discussed throughout the book.

An index is a distinct structure in the database that is built using the


create index statement. It requires its own disk space and holds a copy
of the indexed table data. That means that an index is pure redundancy.
Creating an index does not change the table data; it just creates a new data
structure that refers to the table. A database index is, after all, very much
like the index at the end of a book: it occupies its own space, it is highly
redundant, and it refers to the actual information stored in a different
place.

Clustered Indexes
SQL Server and MySQL (using InnoDB) take a broader view of what
“index” means. They refer to tables that consist of the index structure
only as clustered indexes. These tables are called Index-Organized
Tables (IOT) in the Oracle database.
Chapter 5, “Clustering Data”, describes them in more detail and
explains their advantages and disadvantages.

Searching in a database index is like searching in a printed telephone


directory. The key concept is that all entries are arranged in a well-defined
order. Finding data in an ordered data set is fast and easy because the sort
order determines each entries position.

1
Chapter 1: Anatomy of an Index

A database index is, however, more complex than a printed directory


because it undergoes constant change. Updating a printed directory for
every change is impossible for the simple reason that there is no space
between existing entries to add new ones. A printed directory bypasses this
problem by only handling the accumulated updates with the next printing.
An SQL database cannot wait that long. It must process insert, delete and
update statements immediately, keeping the index order without moving
large amounts of data.

The database combines two data structures to meet the challenge: a doubly
linked list and a search tree. These two structures explain most of the
database’s performance characteristics.

The Index Leaf Nodes


The primary purpose of an index is to provide an ordered representation of
the indexed data. It is, however, not possible to store the data sequentially
because an insert statement would need to move the following entries to
make room for the new one. Moving large amounts of data is very time-
consuming so the insert statement would be very slow. The solution to
the problem is to establish a logical order that is independent of physical
order in memory.

The logical order is established via a doubly linked list. Every node has links
to two neighboring entries, very much like a chain. New nodes are inserted
between two existing nodes by updating their links to refer to the new
node. The physical location of the new node doesn’t matter because the
doubly linked list maintains the logical order.

The data structure is called a doubly linked list because each node refers
to the preceding and the following node. It enables the database to read
the index forwards or backwards as needed. It is thus possible to insert
new entries without moving large amounts of data—it just needs to change
some pointers.

Doubly linked lists are also used for collections (containers) in many
programming languages.

2
The Index Leaf Nodes

Programming Language Name


Java java.util.LinkedList
.NET Framework System.Collections.Generic.LinkedList
C++ std::list

Databases use doubly linked lists to connect the so-called index leaf nodes.
Each leaf node is stored in a database block or page; that is, the database’s
smallest storage unit. All index blocks are of the same size —typically a few
kilobytes. The database uses the space in each block to the extent possible
and stores as many index entries as possible in each block. That means
that the index order is maintained on two different levels: the index entries
within each leaf node, and the leaf nodes among each other using a doubly
linked list.

Figure 1.1. Index Leaf Nodes and Corresponding Table Data


Index Leaf Nodes Table
(sort ed) (not sort ed)
2

lu 1
lu 2
lu 3

4
mn

co mn
co mn
co mn
mn
D
lu

WI

lu
co

RO

co

11 3C AF A 34 1 2
13 F3 91 A 27 5 9
18 6F B2
A 39 2 5
X 21 7 2
21 2C 50
27 0F 1B A 11 1 6
27 52 55
A 35 8 3
X 27 3 2
34 0D 1E
35 44 53 A 18 3 6
39 24 5D A 13 7 4

Figure 1.1 illustrates the index leaf nodes and their connection to the table
data. Each index entry consists of the indexed columns (the key, column 2)
and refers to the corresponding table row (via ROWID or RID). Unlike the
index, the table data is stored in a heap structure and is not sorted at all.
There is neither a relationship between the rows stored in the same table
block nor is there any connection between the blocks.

3
Chapter 1: Anatomy of an Index

The Search Tree (B-Tree)


The index leaf nodes are stored in an arbitrary order —the position on the
disk does not correspond to the logical position according to the index
order. It is like a telephone directory with shuffled pages. If you search
for “Smith” but first open the directory at “Robinson”, it is by no means
granted that Smith follows Robinson. A database needs a second structure
to find the entry among the shuffled pages quickly: a balanced search tree—
in short: the B-tree.

Figure 1.2. B-tree Structure

es
Branch Node Leaf Nodes

od

es
e
N
od

od
ch
N

N
40 4A 1B

an
t

af
o
Ro

Le
Br
43 9F 71
46 A2 D2 11 3C AF
13 F3 91
18 6F B2

21 2C 50
18 27 0F 1B
27 27 52 55
39

46 8B 1C 34 0D 1E
35 44 53
39 24 5D

53 A0 A1 40 4A 1B
43 9F 71
53 0D 79 46 A2 D2

46 46 8B 1C
53 A0 A1
53 0D 79

53 39
46
53
57 55 9C F6

57 55 9C F6 83
98
83 57 B1 C1
57 50 29

83 57 B1 C1 67 C4 6B
83 FF 9D
83 AF E9

57 50 29 84 80 64
86 4C 2F
88 06 5B

89 6A 3E
88 90 7D 9A
94 94 36 D4
67 C4 6B 98

95 EA 37
98 5E B2
83 FF 9D 98 D8 4F

83 AF E9

Figure 1.2 shows an example index with 30 entries. The doubly linked list
establishes the logical order between the leaf nodes. The root and branch
nodes support quick searching among the leaf nodes.

The figure highlights a branch node and the leaf nodes it refers to. Each
branch node entry corresponds to the biggest value in the respective leaf
node. That is, 46 in the first leaf node so that the first branch node entry
is also 46. The same is true for the other leaf nodes so that in the end the

4
The Search Tree (B-Tree)

branch node has the values 46, 53, 57 and 83. According to this scheme, a
branch layer is built up until all the leaf nodes are covered by a branch node.

The next layer is built similarly, but on top of the first branch node level.
The procedure repeats until all keys fit into a single node, the root node.
The structure is a balanced search tree because the tree depth is equal at
every position; the distance between root node and leaf nodes is the same
everywhere.

Note
A B-tree is a balanced tree—not a binary tree.

Once created, the database maintains the index automatically. It applies


every insert, delete and update to the index and keeps the tree in balance,
thus causing maintenance overhead for write operations. Chapter 8,
“Modifying Data”, explains this in more detail.

Figure 1.3. B-Tree Traversal

46 8B 1C
53 A0 A1
46 53 0D 79
39
53
83
57
98 55 9C F6
83
57 B1 C1
57 50 29

Figure 1.3 shows an index fragment to illustrate a search for the key “57”.
The tree traversal starts at the root node on the left-hand side. Each entry
is processed in ascending order until a value is greater than or equal to (>=)
the search term (57). In the figure it is the entry 83. The database follows
the reference to the corresponding branch node and repeats the procedure
until the tree traversal reaches a leaf node.

Important
The B-tree enables the database to find a leaf node quickly.

5
Chapter 1: Anatomy of an Index

The tree traversal is a very efficient operation—so efficient that I refer to it


as the first power of indexing. It works almost instantly—even on a huge data
set. That is primarily because of the tree balance, which allows accessing
all elements with the same number of steps, and secondly because of the
logarithmic growth of the tree depth. That means that the tree depth grows
very slowly compared to the number of leaf nodes. Real world indexes with
millions of records have a tree depth of four or five. A tree depth of six is
hardly ever seen. The box “Logarithmic Scalability” describes this in more
detail.

Slow Indexes, Part I


Despite the efficiency of the tree traversal, there are still cases where an
index lookup doesn’t work as fast as expected. This contradiction has fueled
the myth of the “degenerated index” for a long time. The myth proclaims
an index rebuild as the miracle solution. The real reason trivial statements
can be slow —even when using an index —can be explained on the basis of
the previous sections.

The first ingredient for a slow index lookup is the leaf node chain. Consider
the search for “57” in Figure 1.3 again. There are obviously two matching
entries in the index. At least two entries are the same, to be more precise:
the next leaf node could have further entries for “57”. The database must
read the next leaf node to see if there are any more matching entries. That
means that an index lookup not only needs to perform the tree traversal,
it also needs to follow the leaf node chain.

The second ingredient for a slow index lookup is accessing the table.
Even a single leaf node might contain many hits — often hundreds. The
corresponding table data is usually scattered across many table blocks (see
Figure 1.1, “Index Leaf Nodes and Corresponding Table Data”). That means
that there is an additional table access for each hit.

An index lookup requires three steps: (1) the tree traversal; (2) following the
leaf node chain; (3) fetching the table data. The tree traversal is the only
step that has an upper bound for the number of accessed blocks—the index
depth. The other two steps might need to access many blocks—they cause
a slow index lookup.

6
Slow Indexes, Part I

Logarithmic Scalability
In mathematics, the logarithm of a number to a given base is the
power or exponent to which the base must be raised in order to
1
produce the number [Wikipedia ].
In a search tree the base corresponds to the number of entries per
branch node and the exponent to the tree depth. The example index
in Figure 1.2 holds up to four entries per node and has a tree depth
3
of three. That means that the index can hold up to 64 (4 ) entries. If
4
it grows by one level, it can already hold 256 entries (4 ). Each time
a level is added, the maximum number of index entries quadruples.
The logarithm reverses this function. The tree depth is therefore
log4(number-of-index-entries).
The logarithmic growth enables
Tree Depth Index Entries
the example index to search a
million records with ten tree 3 64
levels, but a real world index is 4 256
even more efficient. The main 5 1,024
factor that affects the tree depth,
6 4,096
and therefore the lookup perfor-
mance, is the number of entries 7 16,384
in each tree node. This number 8 65,536
corresponds to— mathematically
9 262,144
speaking — the basis of the loga-
rithm. The higher the basis, the 10 1,048,576
shallower the tree, the faster the
traversal.
Databases exploit this concept to a maximum extent and put as many
entries as possible into each node— often hundreds. That means that
every new index level supports a hundred times more entries.

1
http://en.wikipedia.org/wiki/Logarithm

7
Chapter 1: Anatomy of an Index

The origin of the “slow indexes” myth is the misbelief that an index lookup
just traverses the tree, hence the idea that a slow index must be caused by a
“broken” or “unbalanced” tree. The truth is that you can actually ask most
databases how they use an index. The Oracle database is rather verbose in
this respect and has three distinct operations that describe a basic index
lookup:

INDEX UNIQUE SCAN


The INDEX UNIQUE SCAN performs the tree traversal only. The Oracle
database uses this operation if a unique constraint ensures that the
search criteria will match no more than one entry.

INDEX RANGE SCAN


The INDEX RANGE SCAN performs the tree traversal and follows the leaf
node chain to find all matching entries. This is the fallback operation
if multiple entries could possibly match the search criteria.

TABLE ACCESS BY INDEX ROWID


The TABLE ACCESS BY INDEX ROWID operation retrieves the row from
the table. This operation is (often) performed for every matched record
from a preceding index scan operation.

The important point is that an INDEX RANGE SCAN can potentially read a large
part of an index. If there is one more table access for each row, the query
can become slow even when using an index.

8
Chapter 2

The Where Clause


The previous chapter described the structure of indexes and explained the
cause of poor index performance. In the next step we learn how to spot
and avoid these problems in SQL statements. We start by looking at the
where clause.

The where clause defines the search condition of an SQL statement, and it
thus falls into the core functional domain of an index: finding data quickly.
Although the where clause has a huge impact on performance, it is often
phrased carelessly so that the database has to scan a large part of the index.
The result: a poorly written where clause is the first ingredient of a slow
query.

This chapter explains how different operators affect index usage and how
to make sure that an index is usable for as many queries as possible. The
last section shows common anti-patterns and presents alternatives that
deliver better performance.

The Equality Operator


The equality operator is both the most trivial and the most frequently
used SQL operator. Indexing mistakes that affect performance are still
very common and where clauses that combine multiple conditions are
particularly vulnerable.

This section shows how to verify index usage and explains how
concatenated indexes can optimize combined conditions. To aid
understanding, we will analyze a slow query to see the real world impact
of the causes explained in Chapter 1.

9
Chapter 2: The Where Clause

Primary Keys
We start with the simplest yet most common where clause: the primary key
lookup. For the examples throughout this chapter we use the EMPLOYEES
table defined as follows:

CREATE TABLE employees (


employee_id NUMBER NOT NULL,
first_name VARCHAR2(1000) NOT NULL,
last_name VARCHAR2(1000) NOT NULL,
date_of_birth DATE NOT NULL,
phone_number VARCHAR2(1000) NOT NULL,
CONSTRAINT employees_pk PRIMARY KEY (employee_id)
);

The database automatically creates an index for the primary key. That
means there is an index on the EMPLOYEE_ID column, even though there is
no create index statement.

The following query uses the primary key to retrieve an employee’s name:

SELECT first_name, last_name


FROM employees
WHERE employee_id = 123

The where clause cannot match multiple rows because the primary key
constraint ensures uniqueness of the EMPLOYEE_ID values. The database does
not need to follow the index leaf nodes —it is enough to traverse the index
tree. We can use the so-called execution plan for verification:

---------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
---------------------------------------------------------------
| 0 |SELECT STATEMENT | | 1 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 2 |
|*2 | INDEX UNIQUE SCAN | EMPLOYEES_PK | 1 | 1 |
---------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
2 - access("EMPLOYEE_ID"=123)

10
Primary Keys

The Oracle execution plan shows an INDEX UNIQUE SCAN — the operation that
only traverses the index tree. It fully utilizes the logarithmic scalability of
the index to find the entry very quickly —almost independent of the table
size.

Tip
The execution plan (sometimes explain plan or query plan) shows the
steps the database takes to execute an SQL statement. Appendix A on
page 165 explains how to retrieve and read execution plans with
other databases.

After accessing the index, the database must do one more step to
fetch the queried data (FIRST_NAME, LAST_NAME) from the table storage:
the TABLE ACCESS BY INDEX ROWID operation. This operation can become a
performance bottleneck —as explained in “Slow Indexes, Part I”— but there
is no such risk in connection with an INDEX UNIQUE SCAN. This operation
cannot deliver more than one entry so it cannot trigger more than one table
access. That means that the ingredients of a slow query are not present
with an INDEX UNIQUE SCAN.

Primary Keys without Unique Index


A primary key does not necessarily need a unique index — you can
use a non-unique index as well. In that case the Oracle database
does not use an INDEX UNIQUE SCAN but instead the INDEX RANGE SCAN
operation. Nonetheless, the constraint still maintains the uniqueness
of keys so that the index lookup delivers at most one entry.
One of the reasons for using non-unique indexes for a primary keys
are deferrable constraints. As opposed to regular constraints, which
are validated during statement execution, the database postpones
the validation of deferrable constraints until the transaction is
committed. Deferred constraints are required for inserting data into
tables with circular dependencies.

11
Chapter 2: The Where Clause

Concatenated Indexes
Even though the database creates the index for the primary key
automatically, there is still room for manual refinements if the key consists
of multiple columns. In that case the database creates an index on all
primary key columns — a so-called concatenated index (also known as multi-
column, composite or combined index). Note that the column order of a
concatenated index has great impact on its usability so it must be chosen
carefully.

For the sake of demonstration, let’s assume there is a company merger.


The employees of the other company are added to our EMPLOYEES table so it
becomes ten times as large. There is only one problem: the EMPLOYEE_ID is
not unique across both companies. We need to extend the primary key by
an extra identifier — e.g., a subsidiary ID. Thus the new primary key has two
columns: the EMPLOYEE_ID as before and the SUBSIDIARY_ID to reestablish
uniqueness.

The index for the new primary key is therefore defined in the following way:

CREATE UNIQUE INDEX employee_pk


ON employees (employee_id, subsidiary_id);

A query for a particular employee has to take the full primary key into
account— that is, the SUBSIDIARY_ID column also has to be used:

SELECT first_name, last_name


FROM employees
WHERE employee_id = 123
AND subsidiary_id = 30;
---------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
---------------------------------------------------------------
| 0 |SELECT STATEMENT | | 1 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 2 |
|*2 | INDEX UNIQUE SCAN | EMPLOYEES_PK | 1 | 1 |
---------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPLOYEE_ID"=123 AND "SUBSIDIARY_ID"=30)

12
Concatenated Indexes

Whenever a query uses the complete primary key, the database can use
an INDEX UNIQUE SCAN — no matter how many columns the index has. But
what happens when using only one of the key columns, for example, when
searching all employees of a subsidiary?

SELECT first_name, last_name


FROM employees
WHERE subsidiary_id = 20;

----------------------------------------------------
| Id | Operation | Name | Rows | Cost |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 106 | 478 |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 106 | 478 |
----------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
1 - filter("SUBSIDIARY_ID"=20)

The execution plan reveals that the database does not use the index. Instead
it performs a FULL TABLE SCAN. As a result the database reads the entire table
and evaluates every row against the where clause. The execution time grows
with the table size: if the table grows tenfold, the FULL TABLE SCAN takes ten
times as long. The danger of this operation is that it is often fast enough
in a small development environment, but it causes serious performance
problems in production.

Full Table Scan


The operation TABLE ACCESS FULL, also known as full table scan, can
be the most efficient operation in some cases anyway, in particular
when retrieving a large part of the table.
This is partly due to the overhead for the index lookup itself, which
does not happen for a TABLE ACCESS FULL operation. This is mostly
because an index lookup reads one block after the other as the
database does not know which block to read next until the current
block has been processed. A FULL TABLE SCAN must get the entire table
anyway so that the database can read larger chunks at a time (multi
block read). Although the database reads more data, it might need to
execute fewer read operations.

13
Chapter 2: The Where Clause

The database does not use the index because it cannot use single columns
from a concatenated index arbitrarily. A closer look at the index structure
makes this clear.

A concatenated index is just a B-tree index like any other that keeps the
indexed data in a sorted list. The database considers each column according
to its position in the index definition to sort the index entries. The first
column is the primary sort criterion and the second column determines the
order only if two entries have the same value in the first column and so on.

Important
A concatenated index is one index across multiple columns.

The ordering of a two-column index is therefore like the ordering of a


telephone directory: it is first sorted by surname, then by first name. That
means that a two-column index does not support searching on the second
column alone; that would be like searching a telephone directory by first
name.

Figure 2.1. Concatenated Index D


_I

Index-Tree
D
_I

RY
EE

IA
D

OY

ID
_I
D

PL

BS
_I

_I

RY
D

EM

SU
_I

RY

EE

IA
EE

IA

OY

ID

123 20 ROWID
OY

ID

PL

BS
PL

BS

EM

SU

123 21 ROWID
EM

SU

123 18 123 27 ROWID


121 25
123 27
126 30
125 30
131 11 124 10 ROWID
126 30
124 20 ROWID
125 30 ROWID

The index excerpt in Figure 2.1 shows that the entries for subsidiary 20 are
not stored next to each other. It is also apparent that there are no entries
with SUBSIDIARY_ID = 20 in the tree, although they exist in the leaf nodes.
The tree is therefore useless for this query.

14
Concatenated Indexes

Tip
Visualizing an index helps in understanding what queries the index
supports. You can query the database to retrieve the entries in index
order (SQL:2008 syntax, see page 144 for proprietary solutions
using LIMIT, TOP or ROWNUM):

SELECT <INDEX COLUMN LIST>


FROM <TABLE>
ORDER BY <INDEX COLUMN LIST>
FETCH FIRST 100 ROWS ONLY;

If you put the index definition and table name into the query, you
will get a sample from the index. Ask yourself if the requested rows
are clustered in a central place. If not, the index tree cannot help find
that place.

We could, of course, add another index on SUBSIDIARY_ID to improve query


speed. There is however a better solution — at least if we assume that
searching on EMPLOYEE_ID alone does not make sense.

We can take advantage of the fact that the first index column is always
usable for searching. Again, it is like a telephone directory: you don’t need
to know the first name to search by last name. The trick is to reverse the
index column order so that the SUBSIDIARY_ID is in the first position:

CREATE UNIQUE INDEX EMPLOYEES_PK


ON EMPLOYEES (SUBSIDIARY_ID, EMPLOYEE_ID);

Both columns together are still unique so queries with the full primary
key can still use an INDEX UNIQUE SCAN but the sequence of index entries is
entirely different. The SUBSIDIARY_ID has become the primary sort criterion.
That means that all entries for a subsidiary are in the index consecutively
so the database can use the B-tree to find their location.

15
Chapter 2: The Where Clause

Important
The most important consideration when defining a concatenated
index is how to choose the column order so it can be used as often
as possible.

The execution plan confirms that the database uses the “reversed” index.
The SUBSIDIARY_ID alone is not unique anymore so the database must
follow the leaf nodes in order to find all matching entries: it is therefore
using the INDEX RANGE SCAN operation.

--------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
--------------------------------------------------------------
| 0 |SELECT STATEMENT | | 106 | 75 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 106 | 75 |
|*2 | INDEX RANGE SCAN | EMPLOYEE_PK | 106 | 2 |
--------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
2 - access("SUBSIDIARY_ID"=20)

In general, a database can use a concatenated index when searching with


the leading (leftmost) columns. An index with three columns can be used
when searching for the first column, when searching with the first two
columns together, and when searching using all columns.

Even though the two-index solution delivers very good select performance
as well, the single-index solution is preferable. It not only saves storage
space, but also the maintenance overhead for the second index. The fewer
indexes a table has, the better the insert, delete and update performance.

To define an optimal index you must understand more than just how
indexes work — you must also know how the application queries the data.
This means you have to know the column combinations that appear in the
where clause.

Defining an optimal index is therefore very difficult for external consultants


because they don’t have an overview of the application’s access paths.
Consultants can usually consider one query only. They do not exploit
the extra benefit the index could bring for other queries. Database
administrators are in a similar position as they might know the database
schema but do not have deep insight into the access paths.

16
Concatenated Indexes

The only place where the technical database knowledge meets the
functional knowledge of the business domain is the development
department. Developers have a feeling for the data and know the access
path. They can properly index to get the best benefit for the overall
application without much effort.

17
Chapter 2: The Where Clause

Slow Indexes, Part II


The previous section explained how to gain additional benefits from an
existing index by changing its column order, but the example considered
only two SQL statements. Changing an index, however, may affect all
queries on the indexed table. This section explains the way databases pick
an index and demonstrates the possible side effects when changing existing
indexes.

The adopted EMPLOYEE_PK index improves the performance of all queries that
search by subsidiary only. It is however usable for all queries that search
by SUBSIDIARY_ID — regardless of whether there are any additional search
criteria. That means the index becomes usable for queries that used to use
another index with another part of the where clause. In that case, if there
are multiple access paths available it is the optimizer’s job to choose the
best one.

The Query Optimizer


The query optimizer, or query planner, is the database component
that transforms an SQL statement into an execution plan. This
process is also called compiling or parsing. There are two distinct
optimizer types.
Cost-based optimizers (CBO) generate many execution plan variations
and calculate a cost value for each plan. The cost calculation is based
on the operations in use and the estimated row numbers. In the
end the cost value serves as the benchmark for picking the “best”
execution plan.
Rule-based optimizers (RBO) generate the execution plan using a hard-
coded rule set. Rule based optimizers are less flexible and are seldom
used today.

18
Slow Indexes, Part II

Changing an index might have unpleasant side effects as well. In our


example, it is the internal telephone directory application that has become
very slow since the merger. The first analysis identified the following query
as the cause for the slowdown:

SELECT first_name, last_name, subsidiary_id, phone_number


FROM employees
WHERE last_name = 'WINAND'
AND subsidiary_id = 30;

The execution plan is:

Example 2.1. Execution Plan with Revised Primary Key Index

---------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
---------------------------------------------------------------
| 0 |SELECT STATEMENT | | 1 | 30 |
|*1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 30 |
|*2 | INDEX RANGE SCAN | EMPLOYEES_PK | 40 | 2 |
---------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("LAST_NAME"='WINAND')
2 - access("SUBSIDIARY_ID"=30)

The execution plan uses an index and has an overall cost value of 30.
So far, so good. It is however suspicious that it uses the index we just
changed— that is enough reason to suspect that our index change caused
the performance problem, especially when bearing the old index definition
in mind— it started with the EMPLOYEE_ID column which is not part of the
where clause at all. The query could not use that index before.

For further analysis, it would be nice to compare the execution plan before
and after the change. To get the original execution plan, we could just
deploy the old index definition again, however most databases offer a
simpler method to prevent using an index for a specific query. The following
example uses an Oracle optimizer hint for that purpose.

SELECT /*+ NO_INDEX(EMPLOYEES EMPLOYEE_PK) */


first_name, last_name, subsidiary_id, phone_number
FROM employees
WHERE last_name = 'WINAND'
AND subsidiary_id = 30;

19
Chapter 2: The Where Clause

The execution plan that was presumably used before the index change did
not use an index at all:

----------------------------------------------------
| Id | Operation | Name | Rows | Cost |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 477 |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 1 | 477 |
----------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
1 - filter("LAST_NAME"='WINAND' AND "SUBSIDIARY_ID"=30)

Even though the TABLE ACCESS FULL must read and process the entire table,
it seems to be faster than using the index in this case. That is particularly
unusual because the query matches one row only. Using an index to find
a single row should be much faster than a full table scan, but in this case
it is not. The index seems to be slow.

In such cases it is best to go through each step of the troublesome execution


plan. The first step is the INDEX RANGE SCAN on the EMPLOYEES_PK index.
That index does not cover the LAST_NAME column—the INDEX RANGE SCAN can
consider the SUBSIDIARY_ID filter only; the Oracle database shows this in
the “Predicate Information” area— entry “2” of the execution plan. There
you can see the conditions that are applied for each operation.

Tip
Appendix A, “Execution Plans”, explains how to find the “Predicate
Information” for other databases.

The INDEX RANGE SCAN with operation ID 2 (Example 2.1 on page 19)
applies only the SUBSIDIARY_ID=30 filter. That means that it traverses the
index tree to find the first entry for SUBSIDIARY_ID 30. Next it follows the
leaf node chain to find all other entries for that subsidiary. The result of the
INDEX RANGE SCAN is a list of ROWIDs that fulfill the SUBSIDIARY_ID condition:
depending on the subsidiary size, there might be just a few ones or there
could be many hundreds.

The next step is the TABLE ACCESS BY INDEX ROWID operation. It uses the
ROWIDs from the previous step to fetch the rows —all columns— from the
table. Once the LAST_NAME column is available, the database can evaluate
the remaining part of the where clause. That means the database has to
fetch all rows for SUBSIDIARY_ID=30 before it can apply the LAST_NAME filter.

20
Slow Indexes, Part II

The statement’s response time does not depend on the result set size
but on the number of employees in the particular subsidiary. If the
subsidiary has just a few members, the INDEX RANGE SCAN provides better
performance. Nonetheless a TABLE ACCESS FULL can be faster for a huge
subsidiary because it can read large parts from the table in one shot (see
“Full Table Scan” on page 13).

The query is slow because the index lookup returns many ROWIDs — one for
each employee of the original company— and the database must fetch them
individually. It is the perfect combination of the two ingredients that make
an index slow: the database reads a wide index range and has to fetch many
rows individually.

Choosing the best execution plan depends on the table’s data distribution
as well so the optimizer uses statistics about the contents of the database.
In our example, a histogram containing the distribution of employees over
subsidiaries is used. This allows the optimizer to estimate the number
of rows returned from the index lookup —the result is used for the cost
calculation.

Statistics
A cost-based optimizer uses statistics about tables, columns, and
indexes. Most statistics are collected on the column level: the number
of distinct values, the smallest and largest values (data range),
the number of NULL occurrences and the column histogram (data
distribution). The most important statistical value for a table is its
size (in rows and blocks).
The most important index statistics are the tree depth, the number
of leaf nodes, the number of distinct keys and the clustering factor
(see Chapter 5, “Clustering Data”).
The optimizer uses these values to estimate the selectivity of the
where clause predicates.

21
Chapter 2: The Where Clause

If there are no statistics available— for example because they were deleted—
the optimizer uses default values. The default statistics of the Oracle
database suggest a small index with medium selectivity. They lead to the
estimate that the INDEX RANGE SCAN will return 40 rows. The execution plan
shows this estimation in the Rows column (again, see Example 2.1 on page
19). Obviously this is a gross underestimate, as there are 1000 employees
working for this subsidiary.

If we provide correct statistics, the optimizer does a better job. The


following execution plan shows the new estimation: 1000 rows for the
INDEX RANGE SCAN. Consequently it calculated a higher cost value for the
subsequent table access.

---------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
---------------------------------------------------------------
| 0 |SELECT STATEMENT | | 1 | 680 |
|*1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 680 |
|*2 | INDEX RANGE SCAN | EMPLOYEES_PK | 1000 | 4 |
---------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("LAST_NAME"='WINAND')
2 - access("SUBSIDIARY_ID"=30)

The cost value of 680 is even higher than the cost value for the execution
plan using the FULL TABLE SCAN (477, see page 20). The optimizer will
therefore automatically prefer the FULL TABLE SCAN.

This example of a slow index should not hide the fact that proper indexing
is the best solution. Of course searching on last name is best supported by
an index on LAST_NAME:

CREATE INDEX emp_name ON employees (last_name);

22
Slow Indexes, Part II

Using the new index, the optimizer calculates a cost value of 3:

Example 2.2. Execution Plan with Dedicated Index

--------------------------------------------------------------
| Id | Operation | Name | Rows | Cost |
--------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 |
|* 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 3 |
|* 2 | INDEX RANGE SCAN | EMP_NAME | 1 | 1 |
--------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
1 - filter("SUBSIDIARY_ID"=30)
2 - access("LAST_NAME"='WINAND')

The index access delivers — according to the optimizer’s estimation— one


row only. The database thus has to fetch only that row from the table: this
is definitely faster than a FULL TABLE SCAN. A properly defined index is still
better than the original full table scan.

The two execution plans from Example 2.1 (page 19) and Example 2.2
are almost identical. The database performs the same operations and
the optimizer calculated similar cost values, nevertheless the second plan
performs much better. The efficiency of an INDEX RANGE SCAN may vary
over a wide range —especially when followed by a table access. Using an
index does not automatically mean a statement is executed in the best way
possible.

23
Chapter 2: The Where Clause

Functions
The index on LAST_NAME has improved the performance considerably, but
it requires you to search using the same case (upper/lower) as is stored in
the database. This section explains how to lift this restriction without a
decrease in performance.

Note
MySQL 5.6 does not support function-based indexing as described
below. As an alternative, virtual columns were planned for MySQL
6.0 but were introduced in MariaDB 5.2 only.

Case-Insensitive Search Using UPPER or LOWER


Ignoring the case in a where clause is very simple. You can, for example,
convert both sides of the comparison to all caps notation:

SELECT first_name, last_name, phone_number


FROM employees
WHERE UPPER(last_name) = UPPER('winand');

Regardless of the capitalization used for the search term or the LAST_NAME
column, the UPPER function makes them match as desired.

Note
Another way for case-insensitive matching is to use a different
“collation”. The default collations used by SQL Server and MySQL do
not distinguish between upper and lower case letters— they are case-
insensitive by default.

24
Case-Insensitive Search Using UPPER or LOWER

The logic of this query is perfectly reasonable but the execution plan is not:

----------------------------------------------------
| Id | Operation | Name | Rows | Cost |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 477 |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 10 | 477 |
----------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
1 - filter(UPPER("LAST_NAME")='WINAND')

It is a return of our old friend the full table scan. Although there is an index
on LAST_NAME, it is unusable —because the search is not on LAST_NAME but
on UPPER(LAST_NAME). From the database’s perspective, that’s something
entirely different.

This is a trap we all might fall into. We recognize the relation between
LAST_NAME and UPPER(LAST_NAME) instantly and expect the database to “see”
it as well. In reality the optimizer’s view is more like this:

SELECT first_name, last_name, phone_number


FROM employees
WHERE BLACKBOX(...) = 'WINAND';

The UPPER function is just a black box. The parameters to the function
are not relevant because there is no general relationship between the
function’s parameters and the result.

Tip
Replace the function name with BLACKBOX to understand the opti-
mizer’s point of view.

Compile Time Evaluation


The optimizer can evaluate the expression on the right-hand side
during “compile time” because it has all the input parameters. The
Oracle execution plan (“Predicate Information” section) therefore
only shows the upper case notation of the search term. This behavior
is very similar to a compiler that evaluates constant expressions at
compile time.

25
Chapter 2: The Where Clause

To support that query, we need an index that covers the actual search term.
That means we do not need an index on LAST_NAME but on UPPER(LAST_NAME):

CREATE INDEX emp_up_name


ON employees (UPPER(last_name));

An index whose definition contains functions or expressions is a so-called


function-based index (FBI). Instead of copying the column data directly into
the index, a function-based index applies the function first and puts the
result into the index. As a result, the index stores the names in all caps
notation.

The database can use a function-based index if the exact expression of the
index definition appears in an SQL statement —like in the example above.
The execution plan confirms this:

--------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
--------------------------------------------------------------
| 0 |SELECT STATEMENT | | 100 | 41 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 100 | 41 |
|*2 | INDEX RANGE SCAN | EMP_UP_NAME | 40 | 1 |
--------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
2 - access(UPPER("LAST_NAME")='WINAND')

It is a regular INDEX RANGE SCAN as described in Chapter 1. The database


traverses the B-tree and follows the leaf node chain. There are no dedicated
operations or keywords for function-based indexes.

Warning
Sometimes ORM tools use UPPER and LOWER without the developer’s
knowledge. Hibernate, for example, injects an implicit LOWER for case-
insensitive searches.

The execution plan is not yet the same as it was in the previous section
without UPPER; the row count estimate is too high. It is particularly strange
that the optimizer expects to fetch more rows from the table than the
INDEX RANGE SCAN delivers in the first place. How can it fetch 100 rows from
the table if the preceding index scan returned only 40 rows? The answer is
that it can not. Contradicting estimates like this often indicate problems
with the statistics. In this particular case it is because the Oracle database

26
Case-Insensitive Search Using UPPER or LOWER

does not update the table statistics when creating a new index (see also
“Oracle Statistics for Function-Based Indexes” on page 28).

After updating the statistics, the optimizer calculates more accurate


estimates:

--------------------------------------------------------------
|Id |Operation | Name | Rows | Cost |
--------------------------------------------------------------
| 0 |SELECT STATEMENT | | 1 | 3 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 3 |
|*2 | INDEX RANGE SCAN | EMP_UP_NAME | 1 | 1 |
--------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
2 - access(UPPER("LAST_NAME")='WINAND')

Note
The so-called “extended statistics” on expressions and column groups
were introduced with Oracle release 11g.

Although the updated statistics do not improve execution performance in


this case— the index was properly used anyway—it is always a good idea to
check the optimizer’s estimates. The number of rows processed for each
operation (cardinality estimate) is a particularly important figure that is
also shown in SQL Server and PostgreSQL execution plans.

Tip
Appendix A, “Execution Plans”, describes the row count estimates in
SQL Server and PostgreSQL execution plans.

SQL Server does not support function-based indexes as described but it does
offer computed columns that can be used instead. To make use of this,
you have to first add a computed column to the table that can be indexed
afterwards:

ALTER TABLE employees ADD last_name_up AS UPPER(last_name);


CREATE INDEX emp_up_name ON employees (last_name_up);

SQL Server is able to use this index whenever the indexed expression
appears in the statement. You do not need to rewrite your query to use the
computed column.

27
Chapter 2: The Where Clause

Oracle Statistics for Function-Based Indexes


The Oracle database maintains the information about the number of
distinct column values as part of the table statistics. These figures
are reused if a column is part of multiple indexes.
Statistics for a function-based index (FBI) are also kept on table level
as virtual columns. Although the Oracle database collects the index
statistics for new indexes automatically (since release 10g), it does not
update the table statistics. For this reason, the Oracle documentation
recommends updating the table statistics after creating a function-
based index:

After creating a function-based index, collect statistics


on both the index and its base table using the DBMS_STATS
package. Such statistics will enable Oracle Database to
correctly decide when to use the index.
—Oracle Database SQL Language Reference

My personal recommendation goes even further: after every index


change, update the statistics for the base table and all its indexes.
That might, however, also lead to unwanted side effects. Coordinate
this activity with the database administrators (DBAs) and make a
backup of the original statistics.

28
User-Defined Functions

User-Defined Functions

Function-based indexing is a very generic approach. Besides functions like


UPPER you can also index expressions like A + B and even use user-defined
functions in the index definition.

There is one important exception. It is, for example, not possible to refer
to the current time in an index definition, neither directly nor indirectly,
as in the following example.

CREATE FUNCTION get_age(date_of_birth DATE)


RETURN NUMBER
AS
BEGIN
RETURN
TRUNC(MONTHS_BETWEEN(SYSDATE, date_of_birth)/12);
END;
/

The function GET_AGE uses the current date (SYSDATE) to calculate the age
based on the supplied date of birth. You can use this function in all parts
of an SQL query, for example in select and the where clauses:

SELECT first_name, last_name, get_age(date_of_birth)


FROM employees
WHERE get_age(date_of_birth) = 42;

The query lists all 42-year-old employees. Using a function-based index is


an obvious idea for optimizing this query, but you cannot use the function
GET_AGE in an index definition because it is not deterministic. That means
the result of the function call is not fully determined by its parameters. Only
functions that always return the same result for the same parameters —
functions that are deterministic— can be indexed.

The reason behind this limitation is simple. When inserting a new row, the
database calls the function and stores the result in the index and there it
stays, unchanged. There is no periodic process that updates the index. The
database updates the indexed age only when the date of birth is changed
by an update statement. After the next birthday, the age that is stored in
the index will be wrong.

29
Chapter 2: The Where Clause

Besides being deterministic, PostgreSQL and the Oracle database require


functions to be declared to be deterministic when used in an index so you
have to use the keyword DETERMINISTIC (Oracle) or IMMUTABLE (PostgreSQL).

Caution
PostgreSQL and the Oracle database trust the DETERMINISTIC or
IMMUTABLE declarations— that means they trust the developer.
You can declare the GET_AGE function to be deterministic and use it in
an index definition. Regardless of the declaration, it will not work as
intended because the age stored in the index will not increase as the
years pass; the employees will not get older—at least not in the index.

Other examples for functions that cannot be “indexed” are random number
generators and functions that depend on environment variables.

Think about it
How can you still use an index to optimize a query for all 42-year-
old employees?

30
Over-Indexing

Over-Indexing

If the concept of function-based indexing is new to you, you might be


tempted to just index everything, but this is in fact the very last thing you
should do. The reason is that every index causes ongoing maintenance.
Function-based indexes are particularly troublesome because they make it
very easy to create redundant indexes.

The case-insensitive search from above could be implemented with the


LOWER function as well:

SELECT first_name, last_name, phone_number


FROM employees
WHERE LOWER(last_name) = LOWER('winand');

A single index cannot support both methods of ignoring the case. We could,
of course, create a second index on LOWER(last_name) for this query, but
that would mean the database has to maintain two indexes for each insert,
update, and delete statement (see also Chapter 8, “Modifying Data”). To
make one index suffice, you should consistently use the same function
throughout your application.

Tip
Unify the access path so that one index can be used by several
queries.

Tip
Always aim to index the original data as that is often the most useful
information you can put into an index.

31
Chapter 2: The Where Clause

Parameterized Queries

This section covers a topic that is skipped in most SQL textbooks:


parameterized queries and bind parameters.

Bind parameters— also called dynamic parameters or bind variables— are an


alternative way to pass data to the database. Instead of putting the values
directly into the SQL statement, you just use a placeholder like ?, :name or
@name and provide the actual values using a separate API call.

There is nothing bad about writing values directly into ad-hoc statements;
there are, however, two good reasons to use bind parameters in programs:

Security
1
Bind variables are the best way to prevent SQL injection .

Performance
Databases with an execution plan cache like SQL Server and the
Oracle database can reuse an execution plan when executing the same
statement multiple times. It saves effort in rebuilding the execution
plan but works only if the SQL statement is exactly the same. If you put
different values into the SQL statement, the database handles it like a
different statement and recreates the execution plan.

When using bind parameters you do not write the actual values but
instead insert placeholders into the SQL statement. That way the
statements do not change when executing them with different values.

1
http://en.wikipedia.org/wiki/SQL_injection

32
Parameterized Queries

Naturally there are exceptions, for example if the affected data volume
depends on the actual values:

99 rows selected.
SELECT first_name, last_name
FROM employees
WHERE subsidiary_id = 20;

---------------------------------------------------------------
|Id | Operation | Name | Rows | Cost |
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 99 | 70 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 99 | 70 |
|*2 | INDEX RANGE SCAN | EMPLOYEE_PK | 99 | 2 |
---------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("SUBSIDIARY_ID"=20)

An index lookup delivers the best performance for small subsidiaries, but a
TABLE ACCESS FULL can outperform the index for large subsidiaries:

1000 rows selected.

SELECT first_name, last_name


FROM employees
WHERE subsidiary_id = 30;
----------------------------------------------------
| Id | Operation | Name | Rows | Cost |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 1000 | 478 |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 1000 | 478 |
----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SUBSIDIARY_ID"=30)

In this case, the histogram on SUBSIDIARY_ID fulfills its purpose. The


optimizer uses it to determine the frequency of the subsidiary ID mentioned
in the SQL query. Consequently it gets two different row count estimates
for both queries.

33
Chapter 2: The Where Clause

The subsequent cost calculation will therefore result in two different cost
values. When the optimizer finally selects an execution plan it takes the
plan with the lowest cost value. For the smaller subsidiary, it is the one
using the index.

The cost of the TABLE ACCESS BY INDEX ROWID operation is highly sensitive
to the row count estimate. Selecting ten times as many rows will elevate
the cost value by that factor. The overall cost using the index is then even
higher than a full table scan. The optimizer will therefore select the other
execution plan for the bigger subsidiary.

When using bind parameters, the optimizer has no concrete values


available to determine their frequency. It then just assumes an equal
distribution and always gets the same row count estimates and cost values.
In the end, it will always select the same execution plan.

Tip
Column histograms are most useful if the values are not uniformly
distributed.
For columns with uniform distribution, it is often sufficient to divide
the number of distinct values by the number of rows in the table.
This method also works when using bind parameters.

If we compare the optimizer to a compiler, bind variables are like program


variables, but if you write the values directly into the statement they
are more like constants. The database can use the values from the SQL
statement during optimization just like a compiler can evaluate constant
expressions during compilation. Bind parameters are, put simply, not
visible to the optimizer just as the runtime values of variables are not
known to the compiler.

From this perspective, it is a little bit paradoxical that bind parameters can
improve performance if not using bind parameters enables the optimizer
to always opt for the best execution plan. But the question is at what price?
Generating and evaluating all execution plan variants is a huge effort that
does not pay off if you get the same result in the end anyway.

34
Parameterized Queries

Tip
Not using bind parameters is like recompiling a program every time.

Deciding to build a specialized or generic execution plan presents a


dilemma for the database. Either effort is taken to evaluate all possible
plan variants for each execution in order to always get the best execution
plan or the optimization overhead is saved and a cached execution plan
is used whenever possible — accepting the risk of using a suboptimal
execution plan. The quandary is that the database does not know if the
full optimization cycle delivers a different execution plan without actually
doing the full optimization. Database vendors try to solve this dilemma
with heuristic methods — but with very limited success.

As the developer, you can use bind parameters deliberately to help resolve
this dilemma. That is, you should always use bind parameters except for
values that shall influence the execution plan.

Unevenly distributed status codes like “todo” and “done” are a good
example. The number of “done” entries often exceeds the “todo” records by
an order of magnitude. Using an index only makes sense when searching
for “todo” entries in that case. Partitioning is another example — that is, if
you split tables and indexes across several storage areas. The actual values
can then influence which partitions have to be scanned. The performance
of LIKE queries can suffer from bind parameters as well as we will see in
the next section.

Tip
In all reality, there are only a few cases in which the actual values
affect the execution plan. You should therefore use bind parameters
if in doubt — just to prevent SQL injections.

The following code snippets show how to use bind parameters in various
programming languages.

35
Another Random Scribd Document
with Unrelated Content
yesterday. I accepted the omen, and we parted in the best of
humours, and with the hope of a speedy meeting.

On the Brenner, September 8, 1786,


Evening.
Hurried, not to say driven, here by necessity, I have reached at last a
resting-place, in a calm, quiet spot, just such as I could wish it to be.
It has been a day which for many years it will be a pleasure to recall.
I left Mittelwald about 6 in the morning, and a sharp wind soon
perfectly cleared the sky. The cold was such as one looks for only in
February. But now, in the splendour of the setting sun, the dark
foreground, thickly planted with fig-trees, and peeping between them
the grey limestone rocks, and behind all, the highest summit of the
mountain covered with snow, and standing out in bold outline against
the deep blue sky, furnish precious and ever-changing images.
One enters the Tyrol by Scharnitz. The boundary line is marked by a
wall which bars the passage through the valley, and abuts on both
sides on the mountains. It looks well: on one side the rocks are
fortified, on the other they ascend perpendicularly. From Seefeld the
road continually grew more interesting, and if from Benedictbeuern to
this place it went on ascending, from height to height, while all the
streams of the neighbouring districts were making for the Isar, now
one caught a sight over a ridge of rocks of the valley of the Inn, and
Inzingen lay before us. The sun was high and hot, so that I was
obliged to throw off some of my coats, for, indeed, with the varying
atmosphere of the day, I am obliged frequently to change my
clothing.
At Zierl one begins to descend into the valley of the Inn. Its situation
is indescribably beautiful, and the bright beams of the sun made it
look quite cheerful. The postilion went faster than I wished, for he
had not yet heard mass, and was anxious to be present at it at
Innspruck, where, as it was the festival of the Nativity of the Virgin
Mary, he hoped to be a devout participant. Accordingly, we rattled
along the banks of the Inn, hurrying by Martinswand, a vast,
precipitous, wall-like rock of limestone. To the spot where the
Emperor Maximilian is said to have lost himself, I ventured to descend
and came up again without a guide, although it is, in any case, a rash
undertaking.
Innsbruck is gloriously situated in a rich, broad
valley, between high rocks and mountains. Innsbruck-
Meteorology.
Everybody and everything was decked out in honour
of the Virgin's Nativity. At first I had some wish to stop there, but it
promised neither rest nor peace. For a little while I amused myself
with the son of my host. At last the people who were to attend to me
came in one by one. For the sake of health and prosperity to the
flocks, they had all gone on a pilgrimage to Wilden, a place of worship
on the mountains, about three miles and a half from the city. About 2
o'clock, as my rolling carriage divided the gay, merry throng, every
one was in holiday garb and promenade.
From Innsbruck the road becomes even still more beautiful; no
powers of description can equal it. The most frequented road,
ascending a gorge which empties its waters into the Inn, offers to the
eye innumerable varieties of scenery. While the road often runs close
to the most rugged rocks—indeed is frequently cut right through them
—one sees the other side above you slightly inclining, and cultivated
with the most surprising skill. On the high and broad-ascending
surface lie valleys, houses, cottages, and cabins, whitewashed,
glittering among the fields and hedges. Soon all changed; the land
becomes available only for pastime, until it, too, terminates on the
precipitous ascent. I have gained some ideas for my scheme of a
creation; none, however, perfectly new and unexpected. I have also
dreamed much of the model I have so long talked about, by which I
am desirous to give a notion of all that is brooding in my own mind,
and which, in nature itself, I cannot point out to every eye.
Now it grew darker and darker; individual objects were lost in the
obscurity; the masses became constantly vaster and grander; at last,
as the whole moved before me like some deeply mysterious figure,
the moon suddenly illuminated the snow-capt summits; and now I am
waiting till morning shall light up this rocky chasm in which I am shut
up on the boundary line of the north and south.
I must again add a few remarks on the weather, which, perhaps,
favours me so highly, in return for the great attention I pay to it. On
the lowlands one has good or bad weather when it is already settled
for either; on the mountains one is present with the beginning of the
change. I have so often experienced this when on my travels, or
walks, or hunting excursions, I have passed days and nights between
the cliffs in the mountain forests. On such occasions, a conceit
occurred to me, which I give you as nothing better, but which,
however, I cannot get rid of, as indeed, generally, such conceits are,
of all things, most difficult to get rid of. I altogether look upon it as a
truth, and so I will now give utterance to it, especially as I have
already so often had occasion to prove the indulgence of my friends.
When we look at the mountains, either closely or from a distance, and
see their summits above us at one time glittering in the sunshine, at
another enveloped in mist, swept round with strong clouds, or
blackened with showers, we are disposed to ascribe it all to the
atmosphere, as we can easily with the eye see and discern its
movements and changes. The mountains, on the other hand, with
their glorious shapes lie before our outward senses immoveable. We
take them to be dead because they are rigid, and we believe them to
be inactive because they are at rest. For a long while, however, I
cannot put off the impulse to ascribe, for the most part, to their
imperceptible and secret influence the changes which are observable
in the atmosphere. For instance, I believe that the mass of the earth
generally, and, therefore, also in an especial way its more
considerable continents do not exercise a constant and invariable
force of attraction, but that this attractive force manifests itself by a
certain pulse which, according to intrinsic, necessary, and probably
also accidental, external causes, increases or decreases. Though all
attempts by other objects to determine this oscillation may be too
limited and rude, the atmosphere furnishes a standard both delicate
and large enough to test their silent operations. When this attractive
force decreases never so little, immediately the decrease in the
gravity and the diminished elasticity of the air indicates this effect.
The atmosphere is now unable to sustain the moisture which is
diffused throughout it either chemically or mechanically; the clouds
lower, and the rain falls and passes to the lowlands. When, however,
the mountains increase their power of attraction, then the elasticity of
the air is again restored, and two important phenomena result. First
of all, the mountains collect around their summits vast masses of
clouds; hold them fast and firm above themselves like second heads,
until, as determined by the contest of electrical forces within them,
they pour down as thunder-showers, rain or mist, and then, on all
that remains the electricity of the air operates, which is now restored
to a capacity of retaining more water, dissolving and elaborating it. I
saw quite clearly the dispersion of a cloudy mass of this kind. It was
hanging on the very highest peak; the red tints of the setting sun still
illuminated it. Slowly and slowly pieces detached themselves from
either end. Some fleecy nebulæ were drawn off and carried up still
higher, and then disappeared, and in this manner, by degrees, the
whole mass vanished, and was strangely spun away before my eyes,
like a distaff, by invisible hands.
If my friends are disposed to laugh at the itinerant
meteorologist and his strange theories, I shall, Meteorology-
Vegetation.
perhaps, give them more solid cause for laughter by
some other of my remarks, for I must confess that, as my journey
was, in fact, a flight from all the unshapely things which tormented
me in latitude 51°, I hoped, in 48°, to meet with a true Goshen. But I
found myself disappointed; for latitude alone does not make a climate
and fine weather, but the mountain-chains—especially such as
intersect the land from east to west. In these, great changes are
constantly going on, and the lands which lie to the north have most to
suffer from them. Thus, further north, the weather throughout the
summer was determined by the great Alpine range on which I am
now writing. Here, for the last few months, it has rained incessantly,
while a south-east or south-west wind carried the showers north-
wards. In Italy they are said to have had fine weather, indeed, a little
too dry.
And now a few words on a kindred subject—the vegetable world,
which, in so many ways, depends on climate and moisture, and the
height of the mountain-ranges. Here, too, I have noticed no
remarkable change, but still an improvement. In the valley before
Innspruck, apples and pears are abundant, while the peaches and
grapes are brought from the Welsh districts, or, in other words, the
Southern Tyrol. Near Innspruck they grow a great deal of Indian corn
and buck wheat, which they call blende. On the Brenner I first saw
the larch, and near Schemberg the pine. Would the harper's daughter
have questioned me about them also?
As regards the plants, I feel still more how perfect a tyro I am. Up to
Munich I saw, I believed, none but those I was well accustomed to. In
truth, my hurried travelling, by day and night, was not favorable to
nicer observation on such objects. Now, it is true, I have my Linnæus
at hand, and his Terminology is well stamped on my brain; but
whence is the time and quiet to come for analysing, which, if I at all
know myself, will never become my forte? I, therefore, sharpen my
eye for the more general features, and when I met with the first
Gentiana near the Walchensee, it struck me that it was always near
the water, that I had hitherto noticed any new plants.
What made me still more attentive was the influence which the
altitude of the mountain region evidently had on plants. Not only did I
meet there with new specimens, but I also observed that the growth
of the old ones was materially altered. While in the lower regions
branches and stalks were stronger and more sappy, the buds stood
closer together, and the leaves broader; the higher you got on the
mountains the stalks and branches became more fragile, the buds
were at greater intervals, and the leaves thinner and more lanceolate.
I noticed this in the case of a Willow and of a Gentiana, and
convinced myself that it was not a case of different species. So also,
near the Walchensee, I noticed longer and thinner rushes than
anywhere else.
The limestone of the Alps, which I have as yet travelled over, has a
greyish tint, and beautiful, singular, irregular forms, although the rock
is divisible into blocks and strata. But as irregular strata occur, and the
rock in general does not crumble equally under the influence of the
weather, the sides and the peaks have a singular appearance. This
kind of rock comes up the Brenner to a great height. In the region of
the Upper Lake I noticed a slight modification. On a micaceous slate
of dark green and grey colours, and thickly veined with quartz, lay a
white, solid limestone, which, in its detritus, sparkled and stood in
great masses, with numberless clefts. Above it I again found
micaceous slate, which, however, seemed to me to be of a softer
texture than the first. Higher up still there was to be seen a peculiar
kind of gneiss, or rather a granitic species which approximated to
gneiss, as is in the district of Ellbogen. Here at the top, and opposite
the Inn, the rock is micaceous slate. The streams which come from
the mountains leave deposits of nothing but this stone, and of the
grey limestone.
Not far from here must be the granitic base on
which all rests. The maps show that one is on the Geology—My
fellow travellers.
side of the true great Brenner, from which the
streams of a wide surrounding district take their rise.
The following is my external judgment of the people. They are active
and straightforward. In form they are pretty generally alike: hazel,
well-opened eyes; with the women brown and well-defined eyebrows,
but with the men light and thick. Among the grey rocks the green
hats of the men have a cheerful appearance. The hats are generally
ornamented with ribbons or broad silk-sashes, and with fringes which
are prettily sewn on. On the other hand, the women disfigure
themselves with white, undressed cotton caps of a large size, very
much like men's nightcaps. These give them a very strange
appearance; but abroad, they wear the green hats of the men, which
become them very much.
I have opportunity of seeing the value the common class of people
put upon peacock's feathers, and, in general, how every variegated
feather is prized. He who wishes to travel through these mountains
will do well to take with him a lot of them. A feather of this kind
produced at the proper moment will serve instead of the ever-
welcome "something to drink."
Whilst I am putting together, sorting, and arranging these sheets, in
such a way that my friends may easily take a review of my fortunes
up to this point, and that I may, at the same time, dismiss from my
soul all that I have lately thought and experienced, I have, on the
other hand, cast many a trembling look on some packets of which I
must give a good but brief account. They are to be my fellow
travellers; may they not exercise too great an influence on my next
few days.
I brought with me to Carlsbad the whole of my MSS. in order to
complete the edition of my works, which Goschen has undertaken.
The unprinted ones I had long possessed in beautiful transcripts, by
the practised hand of Secretary Vögel. This active person
accompanied me on this occasion, in order that I might, if necessary,
command his dexterous services. By this means, and with the never-
failing co-operation of Herder, I was soon in a condition to send to the
printer the first four volumes, and was on the point of doing the same
with the last four. The latter consisted, for the most part, of mere
unfinished sketches, indeed of fragments; for, in truth, my perverse
habit of beginning many plans, and then, as the interest waned,
laying them aside, had gradually gained strength with increasing
years, occupations, and duties.
As I had brought these scraps with me, I readily listened to the
requests of the literary circles of Carlsbad, and read out to them all
that before had remained unknown to the world, which already was
bitter enough in its complaints that much with which it had
entertained itself still remained unfinished.
The celebration of my birthday consisted mainly in sending me several
poems in the name of my commenced but unfinished works. Among
these, one was distinguished above the rest. It was called the Birds. A
deputation of these happy creatures being sent to a true friend
earnestly entreat him to found at once and establish the kingdom so
long promised to them. Not less obvious and playful were the
allusions to my other unfinished pieces, so that, all at once, they
again possessed a living interest for me, and I related to my friends
the designs I had formed, and the entire plans. This gave rise to the
expression of wishes and urgent requests, and gave the game entirely
into Herder's hands, while he attempted to induce me to take back
these papers, and, above all, to bestow upon the Iphigenia the pains
it well deserved. The fragment which lies before me is rather a sketch
than a finished piece; it is written in poetical prose, which occasionally
falls into a sort of Iambical rhythm, and even imitates other syllabic
metres. This, indeed, does great injury to the effect unless it is read
well, and unless, by skilful turns, this defect is carefully concealed. He
pressed this matter on me very earnestly, and as I concealed from
him as well as the rest the great extent of my intended tour, and as
he believed I had nothing more in view than a mountain trip, and as
he was always ridiculing my geographical and mineralogical studies,
he insisted I should act much wiser if, instead of breaking stones, I
would put my hand to this work. I could not but give way to so many
and well-meant remonstrances; but, as yet, I have had no opportunity
to turn my attention to these matters. I now detach Iphigenia from
the bundle and take her with me as my fellow-traveller into the
beautiful and warm country of the South. The days are so long, and
there will be nothing to disturb reflection, while the glorious objects of
the surrounding scenery by no means depress the poetic nerve;
indeed, assisted by movement and the free air, they rather stimulate
and call it forth more quickly and more vividly.

FROM THE BRENNER TO VERONA.

Trent, morning of the 11th Sept.


After full fifty hours, passed in active and constant occupation, I
reached here about 8 o'clock yesterday evening, and soon after
retired to rest, so that I now find myself in condition to go on with my
narrative. On the evening of the 9th, when I had closed the first
portion of my diary, I thought I would try and draw the inn and post-
house on the Brenner, just as it stood. My attempt was unsuccessful,
for I missed the character of the place; I went home therefore in
somewhat of an ill-humor. Mine host asked me if I would not depart,
telling me it was moon-light and the best travelling. Although I knew
perfectly well that, as he wanted his horses early in the morning to
carry in the after-crop (Grummet), and wished to have them home
again in time for that purpose, his advice was given with a view to his
own interest, I nevertheless took it, because it accorded with my own
inclination. The sun reappeared, the air was tolerable, I packed up,
and started about 7 o'clock. The blue atmosphere triumphed over the
clouds, and the evening was most beautiful.
The postilion fell asleep, and the horses set off at a
quick trot down-hill, always taking the well-known Trent.
route. When they came to a village they went
somewhat slower. Then the driver would wake up, and give them a
fresh stimulus, and thus we descended at a good pace with high rocks
on both sides of us, or by the banks of the rapid river Etsch. The
moon arose and shed her light upon the massive objects around.
Some mills, which stood between primæval pine-trees, over the
foaming stream, seemed really everlasting.
When, at 9 o'clock, I had reached Sterzingen, they gave me clearly to
understand, that they wished me off again. Arriving in Mittelwald,
exactly at 12 o'clock, I found everybody asleep except the postilion,
and we were obliged to go on to Brixen, where I was again taken off
in like manner, so that at the dawn of day I was in Colman. The
postilions drove so fast that there was neither seeing nor hearing, and
although I could not help being sorry at travelling through this noble
country with such frightful rapidity; and at night, too, as though I was
flying the place, I nevertheless felt an inward joy, that a favorable
wind blew behind me, and seemed to hurry me towards the object of
my wishes. At day-break I perceived the first vineyard. A woman with
pears and peaches met me, and thus we went on to Teutschen,
where I arrived at 7 o'clock, and then was again hurried on. After I
had again travelled northwards for a while, I at last saw in the bright
sunshine the valley where Botzen is situated. Surrounded by steep
and somewhat high mountains, it is open towards the south, and
sheltered towards the north by the Tyrolese range. A mild, soft air
pervaded the spot. Here the Etsch again winds towards the south.
The hills at the foot of the mountain are cultivated with vines. The
vinestocks are trained over long but low arbourwork; the purple
grapes are gracefully suspended from the top, and ripen in the
warmth of the soil, which is close beneath them. In the bottom of the
valley, which for the most part consists of nothing but meadows, the
vine is cultivated in narrow rows of similar festoons, at a little distance
from each other, while between grows the Indian corn, the stalks of
which at this time are high. I have often seen it ten feet high. The
fibrous' male blossom is not yet cut off, as is the case when
fructification has ceased for some time.
I came to Botzen in a bright sunshine. A good assemblage of
mercantile faces pleased me much. Everywhere one sees the liveliest
tokens. An existence full of purpose, and highly comfortable. In the
square some fruit-women were sitting with round fiat baskets, above
four feet in diameter, in which peaches were arranged side by side, so
as to avoid pressure. Here I thought of a verse, which I had seen
written on the window of the inn at Ratisbon:
Comme les pêches et les melons
Sont pour la bouche d'un Baron,
Ainsi les verges et les bâtons
Sont pour les fous, dit Salomon.
It is obvious that this was written by a northern baron, and no less
clear is it that if he were in this country, he would alter his notions.
At the Botzen fair a brisk silk-trade is carried on. Cloths are also
brought here, and as much leather as can be procured from the
mountain districts. Several merchants, however, came chiefly for the
sake of depositing their money, taking orders, and opening new
credits. I felt I could have taken great delight in examining the various
products that were collected here; but the impulse, the state of
disquiet, which keeps urging me from behind, would not let me rest,
and I must at once hasten from the spot. For my consolation,
however, the whole matter is printed in the statistical papers, and we
can, if we require it, get such instructions from books. I have now to
deal only with the sensible impressions, which no book or picture can
give. In fact, I am again taking interest in the world, I am testing my
faculty of observation, and am trying how far I can go with my
science and my acquirements, how far my eye is clear and sharp, how
much I can take in at a hasty glance, and whether those wrinkles,
that are imprinted upon my heart, are ever again to be obliterated.
Even in these few days, the circumstance that I have had to wait
upon myself, and have always been obliged to keep my attention and
presence of mind on the alert, has given me quite a new elasticity of
intellect. I must now busy myself with the currency, must change,
pay, note down, write, while I formerly did nothing but think, will,
reflect, command, and dictate.
From Botzen to Trent the stage is nine leagues and
runs through a valley, which constantly increases in Botzen—Trent.
fertility. All that merely struggles into vegetation on
the higher mountains, has here more strength and vitality; the sun
shines with warmth, and there is once more belief in a Deity.
A poor woman cried out to me to take her child into my vehicle, as
the hot soil was burning its feet. I did her this little service out of
honour to the strong light of heaven. The child was strangely decked
out, but I could get nothing from it in any way.
The Etsch flows more gently in these parts, and it makes broad
deposits of gravel in many places. On the land, near the river and up
the hills, the planting is so thick and close, that one fancies one thing
will suffocate the other. It is a regular thicket of vineyards, maize,
mulberry trees, apples, pears, quinces, and nuts. The danewort
(Attig) thrives luxuriantly on the walls. Ivy with solid stems runs up
the rocks, on which it spreads itself; the lizards glide through the
interstices, and whatever has life or motion here, reminds one of the
most charming works of art. The braided top-knots of the women, the
bared breasts and light jackets of the men, the fine oxen which you
see driven home from market, the laden asses,—all combine to
produce one of Heinrich Roos's animated pictures. And when evening
draws on, and through the calmness of the air, a few clouds rest upon
the mountains, rather standing than running against the sky, and, as
immediately after sunset, the chirp of the grasshoppers begins to
grow loud, one feels quite at home in the world, and not a mere exile.
I am as reconciled to the place as if I were born and bred in it, and
had now just returned from a whaling expedition to Greenland. Even
the dust, which here as in our fatherland often plays about my
wheels, and which has so long remained strange to me, I welcome as
an old friend. The bell-like voice of the cricket is most piercing, and
far from unpleasant. A cheerful effect is produced, when playful boys
whistle against a field of such singers, and you almost fancy that the
sound on each side is raised by emulation. The evening here is
perfectly mild no less than the day.
If any one who lived in the South, or came from the South, heard my
enthusiasm about these matters, he would consider me very childish.
Ah, what I express here, I long ago was conscious of, while ruffling
under an unkindly sky; and now I love to experience as an exception
the happiness which I hope soon to enjoy as a regular natural
necessity.

Trent, the evening of the 10th Sept.


I have wandered about the city, which has an old, not to say a very
primitive look, though there are new and well-built houses in some of
the streets. In the church there is a picture in which the assembled
council of the Jesuits is represented, listening to a sermon delivered
by the general of the order. I should like to know what he is trying to
palm upon them. The church of these fathers may at once be
recognised from the outside by pilasters of red marble on the façade.
The doors are covered by a heavy curtain, which serves to keep off
the dust. I raised it, and entered a small vestibule. The church itself is
parted off by an iron grating, but so that it can be entirely overlooked.
All was as silent as the grave, for divine service is no longer
performed here. The front door stood open, merely because all
churches must be open at the time of Vespers.
While I stood considering the architecture, which
was, I found, similar to other Jesuit churches, an old Trent.
man stepped in, and at once took off his little black
cap. His old faded black coat indicated that he was a needy priest. He
knelt down before the grating, and rose again after a short prayer.
When he turned round, he said to himself half-aloud: "Well, they have
driven out the Jesuits, but they ought to have paid them the cost of
the church. I know how many thousands were spent on the church
and the seminary." As he uttered this he left the spot, and the curtain
fell behind him. I, however, lifted it again, and kept myself quiet. He
remained a while standing on the topmost step, and said: "The
Emperor did not do it; the Pope did it." With his face turned towards
the street, so that he could not observe me, he continued: "First the
Spaniards, then we, then the French. The blood of Abel cries out
against his brother Cain!" And thus he went down the steps and along
the street, still talking to himself. I should conjecture he is one who,
having been maintained by the Jesuits, has lost his wits in
consequence of the tremendous fall of the order, and now comes
every day to search the empty vessel for its old inhabitants, and, after
a short prayer, to pronounce a curse upon their enemies.
A young man, whom I questioned about the remarkable sights in the
town, showed me a house, which is called the "Devil's house,"
because the devil, who is generally too ready to destroy, is said to
have built it in a single night, with stones rapidly brought to the spot.
However, what is really remarkable about the house, the good man
had not observed, namely, that it is the only house of good taste that
I have yet seen in Trent, and was certainly built by some good Italian,
at an earlier period. At 5 o'clock in the evening I again set off. The
spectacle of yesterday evening was repeated, and at sun-set the
grasshoppers again began to sing. For about a league the journey lies
between walls, above which the grape-espaliers are visible. Other
walls, which are not high enough, have been eked out with stones,
thorns, &c., to prevent passengers from plucking off the grapes. Many
owners sprinkle the foremost rows with lime, which renders the
grapes uneatable, but does not hurt the wine, as the process of
fermentation drives out the heterogeneous matter.
Evening of September 11.
I am now at Roveredo, where a marked distinction of language
begins; hitherto, it has fluctuated between German and Italian. I have
now, for the first time, had a thoroughly Italian postilion, the inn-
keeper does not speak a word of German, and I must put my own
linguistic powers to the test. How delighted I am that the language I
have always most loved now becomes living—the language of
common usage.

Torbole, 12th September (after dinner).


How much do I wish that my friends were with me for a moment to
enjoy the prospect, which now lies before my eyes.
I might have been in Verona this evening but a magnificent natural
phenomenon was in my vicinity—Lake Garda, a splendid spectacle,
which I did not want to miss, and now I am nobly rewarded for taking
this circuitous route. After 5 o'clock I started from Roveredo, up a side
valley, which still pours its waters into the Etsch. After ascending this,
you come to an immense rocky bar, which you must cross in
descending to the lake. Here appeared the finest calcareous rocks for
pictorial study. On descending you come to a little village on the
northern end of the lake, with a little port, or rather landing-place,
which is called Torbole. On my way upwards I was constantly
accompanied by fig-trees, and, descending into the rocky atmosphere,
I found the first olive-tree full of fruit. Here also, for the first time, I
found as a common fruit those little white figs, which the Countess
Lanthieri had promised me.
A door opens from the chamber in which I sit into the court-yard
below. Before this I have placed my table, and taken a rough sketch
of the prospect. The lake may be seen for its whole length, and it is
only at the end, towards the left, that it vanishes from our eyes. The
shore, which is inclosed on both sides by hill and mountain, shines
with a countless number of little hamlets.
After midnight the wind blows from north to south, and he who
wishes to go down the lake must travel at this time, for a few hours
before sunset the current of air changes, and moves northward. At
this time, the afternoon, it blows strongly against me, and pleasantly
qualifies the burning heat of the sun. Volkmann teaches me that this
lake was formerly called "Benacus," and quotes from Virgil a line in
which it was mentioned:

"Fluctibus et fremiter resonans, Benace, marino."

This is the first Latin verse, the subject of which ever stood visibly
before me, and now, in the present moment, when the wind is
blowing stronger and stronger, and the lake casts loftier billows
against the little harbour, it is just as true as it was hundreds of years
ago. Much, indeed, has changed, but the wind still roars about the
lake, the aspect of which gains even greater glory from a line of
Virgil's.
The above was written in a latitude of 45° 50'.

I went out for a walk in the cool of the evening, and now I really find
myself in a new country, surrounded by objects entirely strange. The
people lead a careless, sauntering life. In the first place, the doors are
without locks, but the host assured me that I might be quite at ease,
even though all I had about me consisted of diamonds. In the second
place, the windows are covered with oiled paper instead of glass. In
the third place, an extremely necessary convenience is wanting, so
that one comes pretty close to a state of nature. When I asked the
waiter for a certain place, he pointed down into the court-yard: "Qui,
abasso puo servirsi!" "Dove?" asked I. "Da per tutto, dove vuol," was
the friendly reply. The greatest carelessness is visible everywhere, but
still there is life and bustle enough. During the whole day there is a
constant chattering and shrieking of the female neighbors, all have
something to do at the same time. I have not yet seen an idle
woman.
The host, with Italian emphasis, assured me, that
he felt great pleasure in being able to serve me with Lago Di Garda.
the finest trout. They are taken near Torbole, where
the stream flows down from the mountains, and the fish seeks a
passage upwards. The Emperor farms this fishery for 10,000 gulden.
The fish, which are large, often weighing fifty pounds, and spotted
over the whole body to the head, are not trout, properly so called.
The flavour, which is between that of trout and salmon, is delicate and
excellent.
But my real delight is in the fruit.—in the figs, and in the pears, which
must, indeed, be excellent, where citrons are already growing.

Evening of September 13.


At 3 o'clock this morning I started from Torbole, with a couple of
rowers. At first the wind was so favorable that we put up a sail. The
morning was cloudy but tine, and perfectly calm at day-break. We
passed Limona, the mountain-gardens of which, laid out terrace-
fashion, and planted with citron-trees, have a neat and rich
appearance. The whole garden consists of rows of square white pillars
placed at some distance from each other, and rising up the mountain
in steps. On these pillars strong beams are laid, that the trees planted
between them may be sheltered in the winter. The view of these
pleasant objects was favored by a slow passage, and we had already
passed Malsesine when the wind suddenly changed, took the direction
usual in the day-time, and blew towards the north. Rowing was of
little use against this superior power, and, therefore, we were forced
to land in the harbour of Malsesine. This is the first Venetian spot on
the eastern side of the lake. When one has to do with water we
cannot say, "I will be at this or that particular place to-day." I will
make my stay here as useful as I can, especially by making a drawing
of the castle, which lies close to the water, and is a beautiful object.
As I passed along I took a sketch of it.

Sept. 11th.
The wind, which blew against me yesterday, and drove me into the
harbour of Malsesine, was the cause of a perilous adventure, which I
got over with good humour, and the remembrance of which I still find
amusing. According to my plan, I went early in the morning into the
old castle, which having neither gate nor guard, is accessible to
everybody. Entering the court-yard, I seated myself opposite to the
old tower, which is built on and among the rocks. Here I had selected
a very convenient spot for drawing;—a carved stone seat in the wall,
near a closed door, raised some three or four feet high, such as we
also find in the old buildings in our own country.
I had not sat long before several persons entered
the yard, and walked backwards and forwards, An incident at
Malsesine.
looking at me. The multitude increased, and at last
so stood as completely to surround me. I remarked that my drawing
had excited attention; however, I did not allow myself to be disturbed,
but quietly continued my occupation. At last a man, not of the most
prepossessing appearance, came up to me, and asked me what I was
about. I replied that I was copying the old tower, that I might have
some remembrance of Malsesine. He said that this was not allowed,
and that I must leave off. As he said this in the common Venetian
dialect, so that I understood him with difficulty, I answered, that I did
not understand him at all. With true Italian coolness he took hold of
my paper, and tore it, at the same time letting it remain on the
pasteboard. Here I observed an air of dissatisfaction among the by-
standers; an old woman in particular said that it was not right, but
that the podestà ought to be called, who was the best judge of such
matters. I stood upright on the steps, having my back against the
door, and surveyed the assembly, which was continually increasing.
The fixed eager glances, the good humoured expression of most of
the faces, and all the other characteristics of a foreign mob, made the
most amusing impression upon me. I fancied that I could see before
me the chorus of birds, which, as Treufreund, I had often laughed at,
in the Ettersburg theatre. This put me in excellent humour, and when
the podestà came up with his actuary, I greeted him in an open
manner, and when he asked me why I was drawing the fortification,
modestly replied, that I did not look upon that wall as a fortification. I
called the attention of him and the people to the decay of the towers
and walls, and to the generally defenceless position of the place,
assuring him that I thought I only saw and drew a ruin.
I was answered thus: "If it was only a ruin, what could there be
remarkable about it?" As I wished to gain time and favour, I replied
very circumstantially, that they must be well aware how many
travellers visited Italy, for the sake of the ruins only, that Rome, the
metropolis of the world, having suffered the depredations of
barbarians, was now full of ruins, which had been drawn hundreds of
times, and that all the works of antiquity were not in such good
preservation as the amphitheatre at Verona, which I hoped soon to
see.
The podestà, who stood before me, though in a less elevated position,
was a tall man, not exactly thin, of about thirty years of age. The flat
features of his spiritless face perfectly accorded with the slow
constrained manner, in which he put his questions. Even the actuary,
a sharp little fellow, seemed as if he did not know what to make of a
case so new, and so unexpected. I said a great deal of the same sort;
the people seemed to take my remarks good naturedly, and on
turning towards some kindly female faces, I thought I could read
assent and approval.
When, however, I mentioned the amphitheatre at Verona, which in
this country, is called the "Arena," the actuary, who had in the
meanwhile collected himself, replied, that this was all very well,
because the edifice in question was a Roman building, famed
throughout the world. In these towers, however, there was nothing
remarkable, excepting that they marked the boundary between the
Venetian domain and Austrian Empire, and therefore espionage could
not be allowed. I answered by explaining at some length, that not
only the Great and Roman antiquities, but also those of the Middle-
Ages were worth attention. They could not be blamed, I granted, if,
having been accustomed to this building from their youth upwards,
they could not discern in it so many picturesque beauties as I did.
Fortunately the morning sun, shed the most beautiful lustre on the
tower, rocks, and walls, and I began to describe the scene with
enthusiasm. My audience, however, had these much lauded objects
behind them, and as they did not wish to turn altogether away from
me, they all at once twisted their heads, like the birds, which we call
"wry necks" (Wendehälse), that they might see with their eyes, what I
had been lauding to their ears. Even the podestà turned round
towards the picture I had been describing, though with more dignity
than the rest. This scene appeared to me so ridiculous that my good
humour increased, and I spared them nothing—least of all, the ivy,
which had been suffered for ages to adorn the rocks and walls.
The actuary retorted, that this was all very good, but the Emperor
Joseph was a troublesome gentleman, who certainly entertained
many evil designs against Venice; and I might probably have been
one of his subjects, appointed by him, to act as a spy on the borders.
"Far from belonging to the Emperor," I replied, "I can boast, as well as
you, that I am a citizen of a republic, which also governs itself, but
which is not, indeed, to be compared for power and greatness to the
illustrious state of Venice, although in commercial activity, in wealth,
and in the wisdom of its rulers, it is inferior to no state in Germany. I
am a native of Frankfort-on-the-Main, a city, the name and fame of
which has doubtless reached you."
"Of Frankfort-on-the-Main!" cried a pretty young
woman, "then, Mr. Podestà, you can at once see all An incident at
Malsesine.
about the foreigner, whom I look upon as an honest
man. Let Gregorio be called; he has resided there a long time, and
will be the best judge of the matter."
The kindly faces had already increased around me, the first adversary
had vanished, and when Gregorio came to the spot, the whole affair
took a decided turn in my favor. He was a man upwards of fifty, with
one of those well-known Italian faces. He spoke and conducted
himself like one, who feels that something foreign is not foreign to
him, and told me at once that he had seen service in Bolongari's
house, and would be delighted to hear from me something about this
family and the city in general, which had left a pleasant impression in
his memory. Fortunately his residence at Frankfort had been during
my younger years, and I had the double advantage of being able to
say exactly how matters stood in his time, and what alteration had
taken place afterwards. I told him about all the Italian families, none
of whom had remained unknown to me. With many particulars he was
highly delighted, as, for instance, with the fact that Herr Alessina had
celebrated his "golden wedding,"[2] in the year 1774, and that a
medal had been struck on the occasion, which was in my possession.
He remembered that the wife of this wealthy merchant was by birth a
Brentano. I could also tell him something about the children and
grand-children of these families, how they had grown up, and had
been provided for and married, and had multiplied themselves in their
descendants.
When I had given the most accurate information about almost
everything which he asked, his features alternately expressed
cheerfulness and solemnity. He was pleased and touched, while the
people cheered up more and more, and could not hear too much of
our conversation, of which—it must be confessed—he was obliged to
translate a part into their own dialect.
At last he said: "Podestà, I am convinced that this is a good,
accomplished, and well-educated gentleman, who is travelling about
to acquire instruction. Let him depart in a friendly manner, that he
may speak well of us to his fellow-countrymen, and induce them to
visit Malsesine, the beautiful situation of which is well worthy the
admiration of foreigners. I gave additional force to these friendly
words by praising the country, the situation, and the inhabitants, not
forgetting to mention the magistrates as wise and prudent
personages."
This was well received, and I had permission to visit the place at
pleasure, in company with Master Gregorio. The landlord, with whom
I had put up, now joined us, and was delighted at the prospect of the
foreign guests, who would crowd upon him, when once the
advantages of Malsesine were properly known. With the most lively
curiosity he examined my various articles of dress, but especially
envied me the possession of a little pistol, which slipped conveniently
into the pocket. He congratulated those who could carry such pretty
weapons, this being forbidden in his country under the severest
penalties. This friendly but obtrusive personage I sometimes
interrupted to thank my deliverer. "Do not thank me," said honest
Gregorio, "for you owe me nothing. If the Podestà had understood his
business, and the Actuary had not been the most selfish man in the
world, you would not have got off so easily. The former was still more
puzzled than you, and the latter would have pocketed nothing by your
arrest, the information, and your removal to Verona. This he rapidly
thought over, and you were already free, before our dialogue was
ended."
Towards the evening the good man took me into his vineyard, which
was very well situated, down along the lake. We were accompanied
by his son, a lad of fifteen, who was forced to climb the trees, and
pluck me the best fruit, while the old man looked out for the ripest
grapes.
While thus placed between these two kindhearted people, both
strange to the world, alone, as it were, in the deep solitude of the
earth, I felt, in the most lively manner, as I reflected on the day's
adventure, what a whimsical being Man is—how the very thing, which
in company he might enjoy with ease and security, is often rendered
troublesome and dangerous, from his notion, that he can appropriate
to himself the world and its contents after his own peculiar fashion.
Towards midnight my host accompanied me to the barque, carrying
the basket of fruit with which Gregorio had presented me, and thus,
with a favorable wind, I left the shore, which had promised to become
a Læstrygonicum shore to me.
[2] The fiftieth anniversary of a wedding-day is so called in
Germany. Trans.

And now for my expedition on the lake. It ended


happily, after the noble aspect of the water, and of Lago Di Garda.
the adjacent shore of Brescia had refreshed my very
heart. On the western side, where the mountains cease to be
perpendicular, and near the lake, the land becomes more flat,
Garignano, Bojaco, Cecina, Toscolan, Maderno, Verdom, and Salo,
stand all in a row, and occupy a reach of about a league and a half;
most of them being built in long streets. No words can express the
beauty of this richly inhabited spot. At 10 o'clock in the morning I
landed at Bartolino, placed my luggage on one mule and myself on
another. The road went now over a ridge, which separates the valley
of the Etsch from the hollow of the lake. The primæval waters seem
to have driven against each other from both sides, in immense
currents, and to have raised this colossal dam of gravel. A fertile soil
was deposited upon the gravel at a quieter period, but the labourer is
constantly annoyed by the appearance of the stones on the surface.
Every effort is made to get rid of them, they are piled in rows and
layers one on another, and thus a sort of thick wall is formed along
the path. The mulberry-trees, from a want of moisture, have a dismal
appearance at this elevation. Springs there are none. From time to
time puddles of collected rain-water may be found, with which the
mules and even their drivers quench their thirst. Some wheels are
placed on the river beneath, to water, at pleasure, those plantations
that have a lower situation.
The magnificence of the new country, which opens on you as you
descend, surpasses description. It is a garden a mile long and broad,
which lies quite flat at the foot of tall mountains and steep rocks, and
is as neatly laid out as possible. By this way, about 1 o'clock on the
10th of September, I reached Verona, where I first write this, finish,
and put together the first part of my diary, and indulge in the pleasing
hope of seeing the amphitheatre in the evening.
Concerning the weather of these days I have to make the following
statement:—The night from the 9th to the 10th was alternately clear
and cloudy, the moon had always a halo round it. Towards 5 o'clock in
the morning all the sky was overcast with gray, not heavy clouds,
which vanished with the advance of day. The more I descended the
finer was the weather. As at Botzen the great mass of the mountains
took a northerly situation, the air displayed quite another quality.
From the different grounds in the landscape, which were separated
from each other in the most picturesque manner, by a tint more or
less blue, it might be seen, that the atmosphere was full of vapors
equally distributed, which it was able to sustain, and which, therefore,
neither fell in the shape of dew, nor were collected in the form of
clouds. As I descended further I could plainly observe, that all the
exhalations from the Botzen valley, and all the streaks of cloud which
ascended from the more southern mountains, moved towards the
higher northern regions, which they did not cover, but veiled with a
kind of yellow fog. In the remotest distance, over the mountains, I
could observe what is called a "water-gull." To the south of Botzen
they have had the finest weather all the summer, only a little water
(they say aqua to denote a light rain), from time to time, and then a
return of sunshine. Yesterday a few drops occasionally fell, and the
sun throughout continued shining. They have not had so good a year
for a long while; everything turns out well; the bad weather they have
sent to us.
I mention but slightly the mountains and the species of stone, since
Ferber's travels to Italy, and Hacquet's journey along the Alps, give
sufficient information respecting this district. A quarter of a league
from the Brenner, there is a marble quarry, which I passed at twilight.
It may, nay, must lie upon mica-slate as on the other side. This I
found near Colman, just as it dawned; lower down there was an
appearance of porphyry. The rocks were so magnificent, and the
heaps were so conveniently broken up along the highway, that a
"Voigt" cabinet might have been made and packed up at once.
Without any trouble of that kind I can take a piece, if it is only to
accustom my eyes and my curiosity to a small quantity. A little below
Colman, I found some porphyry, which splits into regular plates, and
between Brandrol and Neumark some of a similar kind, in which,
however, the laminæ separated in pillars. Ferber considered them to
be volcanic productions, but that was fourteen years ago, when all the
world had its head on fire. Even Hacquet ridicules the notion.
Of the people I can say but little, and that is not
very favorable. On my descent from the Brenner, I From Brenner to
Verona.
discovered, as soon as day came, a decided change
of form, and was particularly displeased by the pale brownish
complexion of the women. Their features indicated wretchedness, the
children looked equally miserable;—the men somewhat better. I
imagine that the cause of this sickly condition may be found in the
frequent consumption of Indian corn and buckwheat. Both the former,
which they also call "Yellow Blende," and the latter, which is called
"Black Blende," is ground, made into a thick pap with water, and thus
eaten. The Germans on this side, pull out the dough, and fry it in
butter. The Italian Tyrolese, on the contrary, eat it just as it is, often
with scrapings of cheese, and do not taste meat throughout the year.
This necessarily glues up and stops the alimentary channels,
especially with the women and children, and their cachectic
complexion is an indication of the malady. They also eat fruit and
green beans, which they boil down in water, and mix with oil and
garlic. I asked if there were no rich peasants. "Yes, indeed," was the
reply. "Don't they indulge themselves at all? don't they eat anything
better?" "No, they are used to it." "What do they do with their money
then? how do they lay it out?" "Oh, they have their ladies, who relieve
them of that." This is the sum and substance of a conversation with
mine host's daughter at Botzen.
I also learned from her, that the vine-tillers were the worst off,
although they appeared to be the most opulent, for they were in the
hands of commercial towns-people, who advanced them enough to
support life in the bad seasons, and in winter took their wine at a low
price. However, it is the same thing everywhere.
My opinion concerning the food is confirmed by the fact, that the
women who inhabit the towns appear better and better. They have
pretty plump girlish faces, the body is somewhat too short in
proportion to the stoutness, and the size of the head, but sometimes
the countenances have a most agreable expression. The men we
already know through the wandering Tyrolese. In the country their
appearance is less fresh than that of the women, perhaps because the
latter have more bodily labour, and are more in motion, while the
former sit at home as traders and workmen. By the Garda Lake I
found the people very brown, without the slightest tinge of red in
their cheeks; however they did not look unhealthy, but quite fresh and
comfortable. Probably the burning sunbeams, to which they are
exposed at the foot of their mountains, are the cause of their
complexion.

FROM VERONA TO VENICE.

Verona, Sept. 16th.


Well then, the amphitheatre is the first important monument of the
old times that I have seen—and how well it is preserved! When I
entered, and still more when I walked round the edge of it at the top,
it seemed strange to me, that I saw something great, and yet,
properly speaking, saw nothing. Besides I do not like to see it empty,
I should like to see it full of people, just as, in modern times, it was
filled up in honour of Joseph I. and Pius VI. The Emperor, although his
eye was accustomed to human masses, must have been astonished.
But it was only in the earliest times, that it produced its full effect,
when the people was more a people than it is now. For, properly
speaking, such an amphitheatre is constructed to give the people an
imposing view of itself,—to cajole itself.
When anything worth seeing occurs on the level ground, and any one
runs to the spot, the hindermost try by every means to raise
themselves above the foremost; they get upon benches, roll casks,
bring up vehicles, lay planks in every direction, occupy the
neighbouring heights, and a crater is formed in no time.
If the spectacle occur frequently on the same spot, light scaffoldings
are built for those who are able to pay, and the rest of the multitude
must get on as it can. Here the problem of the architect is to satisfy
this general want. By means of his art he prepares such a crater,
making it as simple as possible, that the people itself may constitute
the decoration. When the populace saw itself so assembled, it must
have been astonished at the sight, for whereas it was only
accustomed to see itself running about in confusion, or to find itself
crowded together without particular rule or order, so must this many-
headed, many-minded, wandering animal now see itself combined
into a noble body, made into a definite unity, bound and secured into
a mass, and animated as one form by one mind. The simplicity of the
oval is most pleasingly obvious to every eye, and every head serves
as a measure to show the vastness of the whole. Now we see it
empty, we have no standard, and do not know whether it is large or
small.
The Veronese deserve commendation for the high
preservation in which this edifice is kept. It is built Verona.
of a reddish marble, which has been affected by the
atmosphere, and hence the steps which have been eaten, are
continually restored, and look almost all new. An inscription makes
mention of one Hieronymus Maurigenus, and of the incredible
industry, which he has expended on this monument. Of the outer wall
only a piece remains, and I doubt whether it was ever quite finished.
The lower arches, which adjoin the large square, called "Il Bra," are
let out to workmen, and the reanimation of these arcades produces a
cheerful appearance.

Verona, Sept. 16.


The most beautiful gate, which, however, always remains closed, is
called "Porta stupa," or "del Pallio." As a gate, and considering the
great distance from which it is first seen, it is not well conceived, and
it is not till we come near it, that we recognise the beauty of the
structure.
All sorts of reasons are given to account for its being closed. I have,
however, a conjecture of my own. It was manifestly the intention of
the artist to cause a new Corso to be laid out from this gate, for the
situation, or the present street, is completely wrong. On the left side
there is nothing but barracks; and the line at right angles from the
middle of the gate leads to a convent of nuns, which must certainly
have come down. This was presently perceived, and besides the rich
and higher classes might not have liked to settle in the remote
quarter. The artist perhaps died, and therefore the door was closed,
and so an end was put to the affair.

Verona, Sept. 16.


The portico of the theatre, consisting of six large Ionic columns, looks
handsome enough. So much the more puny is the appearance of the
Marchese di Maffei's bust, which as large as life, and in a great wig,
stands over the door, and in front of a painted niche, which is
supported by two Corinthian columns. The position is honorable, but
to be in some degree proportionate to the magnitude and solidity of
the columns, the bust should have been colossal. But now placed as it
is on a corbel, it has a mean appearance, and is by no means in
harmony with the whole.
The gallery, which incloses the fore-court, is also small, and the
channelled Doric dwarfs have a mean appearance by the side of the
smooth Ionic giants. But we pardon this discrepancy on account of
the fine institution, which has been founded among the columns. Here
is kept a number of antiquities, which have mostly been dug up in and
about Verona. Something, they say, has even been found in the
Amphitheatre. There are Etruscan, Greek, and Roman specimens,
down to the latest times, and some even of more modern date. The
bas-reliefs are inserted in the walls, and provided with the numbers,
which Maffei gave them, when he described them in his work:
"Verona illustrata." There are altars, fragments of columns, and other
relics of the sort; an admirable tripod of white marble, upon which
there are genii occupied with the attributes of the gods. Raphael has
imitated and improved this kind of thing in the scrolls of the
Farnesina.
The wind which blows from the graves of the ancients, comes
fragrantly over hills of roses. The tombs give touching evidences of a
genuine feeling, and always bring life back to us. Here is a man, by
the side of his wife, who peeps out of a niche, as if it were a window.
Here are father and mother, with their son between them, eyeing
each other as naturally as possible. Here a couple are grasping each
other's hands. Here a father, resting on his couch, seems to be
amused by his family. The immediate proximity of these stones was to
me highly touching. They belong to a later school of art, but are
simple, natural, and generally pleasing. Here a man in armour is on
his knees in expectation of a joyful resurrection. With more or less of
talent the artist has produced the mere simple presence of the
persons, and has thus given a permanent continuation to their
existence. They do not fold their hands, they do not look towards
heaven, but they are here below just what they were and just what
they are. They stand together, take interest in each other, love one
another, and this is charmingly expressed on the stone, though with a
certain want of technical skill. A marble pillar, very richly adorned,
gave me more new ideas.
Laudable as this institution is, we can plainly
perceive that the noble spirit of preservation, by Verona.
which it was founded, is no longer continued. The
valuable tripod will soon be ruined, placed as it is in the open air, and
exposed to the weather towards the west. This treasure might easily
be preserved in a wooden case.
The palace of the Proveditore, which is begun, might have afforded a
fine specimen of architecture, if it had been finished. Generally
speaking, the nobili build a great deal, but unfortunately every one
builds on the site of his former residence, and often, therefore, in
narrow lanes. Thus, for instance, a magnificent façade to a seminary
is now building in an alley of tire remotest suburb.

While, with a guide, whom I had accidentally picked up, I passed


before the great solemn gate of a singular building, he asked me
good-humouredly, whether I should not like to step into the court for
a while. It was the palace of justice, and the court, on account of the
height of the building, looked only like an enormous wall. Here, he
told me, all the criminals and suspicious persons are confined. I
looked around, and saw that round all the stories there were open
passages' fitted with iron balustrades, which passed by numerous
doors. The prisoner, as he stepped out of his dungeon to be led to
trial, stood in the open air, and was exposed to the gaze of all
passers, and because there were several trial-rooms, the chains were
rattling, now over this, now over that passage, in every story. It was a
hateful sight, and I do not deny that the good humour, with which I
had dispatched my "Birds," might here have come into a strait.

I walked at sunset upon the margin of the crater-like amphitheatre,


and enjoyed the most splendid prospect over the town and the
surrounding country. I was quite alone, and multitudes of people were
passing below me on the hard stones of the Bra; men of all ranks,
and women of the middle-ranks were walking. The latter in their black
outer garments look, in this bird's-eye view, like so many mummies.
The Zendale and the Veste, which serves this class in the place of an
entire wardrobe, is a costume completely fitted for a people that does
not care much for cleanliness, and yet always likes to appear in
public, sometimes at church, sometimes on the promenade. The Veste
is a gown of black taffeta, which is thrown over other gowns. If the
lady has a clean white one beneath, she contrives to lift up the black
one on one side. This is fastened on so, as to cut the waist, and to
cover the lappets of a corset, which may be of any colour. The
Zendale is a large hood with long ears; the hood itself is kept high
above the head by a wire-frame, while the ears are fastened round
the body like a scarf, so that the ends fall down behind.

Verona, Sept. 16.


When I again left the Arena to-day, I came to a modern public
spectacle, about a thousand paces from the spot. Four noble
Veronese were playing ball against four people of Vicenza. This
pastime is carried on among the Veronese themselves all the year
round, about two hours before night. On this occasion there was a far
larger concourse of people than usual, on account of the foreign
adversaries. The spectators seem to have amounted to four or five
thousand. I did not see women of any rank.
When, a little while ago, I spoke of the necessities of the multitude in
such a case, I described the natural accidental amphitheatre as
arising just in the manner, in which I saw the people raised one over
another on this occasion. Even at a distance I could hear the lively
clapping of hands, which accompanied every important stroke. The
game is played as follows: Two boards, slightly inclined, are placed at
a convenient distance from each other. He who strikes off the ball
stands at the higher end, his right hand is armed with a broad
wooden ring, set with spikes. While another of his party throws the
ball to him, he runs down to meet it, and thus increases the force of
the blow with which he strikes it. The adversaries try to beat it back,
and thus it goes backwards and forwards till, at last, it remains on the
ground. The most beautiful attitudes, worthy of being imitated in
marble, are thus produced. As there are none but well-grown active
young people, in a short, close, white dress, the parties are only
distinguished by a yellow mark. Particularly beautiful is the attitude
into which the man on the eminence falls, when he runs down the
inclined plain, and raises his arm to strike the ball;—it approaches that
of the Borghesian gladiator.
It seemed strange to me that they carry on this exercise by an old
lime-wall, without the slightest convenience for spectators; why is it
not done in the amphitheatre, where there would be such ample
room?

Verona, September 17.


What I have seen of pictures I will but briefly touch upon, and add
some remarks. I do not make this extraordinary tour for the sake of
deceiving myself, but to become acquainted with myself by means of
these objects. I therefore honestly confess that of the painter's art—of
his manipulation, I understand but little. My attention, and
observation, can only be directed to the practical part, to the subject,
and the general treatment of it.
S. Georgio is a gallery of good pictures, all altar-
pieces, and all remarkable, if not of equal value. But Verona.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like