Professional Documents
Culture Documents
Introduction To Netezza
Introduction To Netezza
Bank of America
Topics
• Netezza Architecture
• SQL Differences
System Architecture
System Capacity
• System Capacity
• The system is ‘full’ when any one SPU is full
• A badly skewed distribution of a large table may fill up a SPU prematurely
• Try to keep skew under 10% (5% off average) for very large tables
• System Performance
• SQL code snippets are executed synchronously among all SPUs
• The total execution time for a snippet is the longest time among the SPUs
• The total execution time for a query is the sum of the longest times for each snippet
• Snippet execution time is proportionally related to the amount of data a SPU needs to process
• A query will only run as fast as the slowest SPU
• Aginity Workbench
• Provides ability to redistribute existing tables
• Allows you to view a table’s distribution
• The query will execute in parallel across all SPUs without data
sharing because:
• Both tables are distributed on the same key (ID_TS)
• ID_TS is used to join the tables
• A zone map records the high and low values of columns for
rows in a data block on disk
• Netezza uses zone maps to skip data blocks that do not satisfy
query predicates, speeding query execution
• Specify up to 4 columns
• Identifiers
• Data Types
• Functions
• Command differences
• Regular Identifier
• Is case insensitive
• Must begin with a letter
• Contain letters, digits, underscores, dollar sign ($)
• Delimited Identifier
• Enclosed in double quotes
• Is case sensitive
• May include spaces, other special symbols and reserved words
• May begin with any allowable character
Know Your Customers. Grow Your Business.
• Character types
• CHAR, VARCHAR: ASCII data, 64,000 maximum length
• NCHAR, NVARCHAR: Unicode data, 16,000 maximum length
• Logical Types
• BOOLEAN (or BOOL) True/false value, 1 byte
• Temporal Types
• Time maintained to microsecond (6 decimal places)
• DATE Date with no time – 4 bytes
• TIME Time with no date – 8 bytes
• TIME WITH TIME ZONE Time with time zone information – 12 bytes
• TIMESTAMP Date and time – 8 bytes
• INTERVAL Know Time interval,
Your non-standard
Customers. implementation
Grow Your Business.
• Maintained in seconds
• Ignores unit declarations, literals require explicit units
• Month assumed to be 30 days
to Netezza –| Prepared for Bank of America
27
Ipsos Loyalty
Introduction © 2011 Aginity LLC Ipsos, January 2007
Internal Data Types (pseudo-columns)
• ROWID
• Unique row identifier, assigned when row is inserted
• Not sequential in table
• Value range 100,000 - 9,223,372,036,854,775,807
• Will numbers ever repeat?
• If a table contains 2 billion rows and takes 3 minutes to copy
• And if the table is copied repeatedly and continuously (add 2 billion rows every 3 minutes)
• It will take over 24,000 years to run out of numbers
• Netezza hopes you would have upgraded before then
• CREATEXID, DELETEXID
• Transaction ID that created and deleted the row.
• If DELETEXID > 0, row has been deleted
• You can not see deleted rows using SQL
Know Your Customers. Grow Your Business.
• DATASLICEID
• Identifies the SPU holding the row
• CASE
Searched form: Value form:
CASE CASE <test-value>
WHEN <search-condition-1> THEN <result-1> WHEN <comparand-value-1> THEN <result-1>
WHEN <search-condition-2> THEN <result-2> WHEN <comparand-value-2> THEN <result-2>
... ...
WHEN <search-condition-n> THEN <result-n> WHEN <comparand-value-n> THEN <result-n>
ELSE <default-result> ELSE <default-result>
END END
Search conditions can be arbitrarily complex and Test values, comparand values, and results can be
results can be expressions. expressions.
• DECODE
• Same as Oracle DECODE
• decode(<expr>,<search1>,<result1>, …<search N>,<result N>,<default>)
• Current time
• Use NOW() or CURRENT_TIMESTAMP
• TIMEOFDAY() returns a verbose date string. Example: ‘Mon Jan 24 16:12:05 2011 EST’
• Date Conversion
• Date literal is in MM/DD/YYYY format (default). Example: ‘1/1/3000’
• TO_DATE(<text>, <template>) Converts string to DATE data type
Template describes format of date string.
Example: TO_DATE(‘24 Jan 2011’, ‘DD Mon YYYY’)
• TO_TIMESTAMP (<text>, <template>) Converts string to TIMESTAMP data type
• TO_CHAR(date or timestamp, <template>) Converts date or timestamp to string
• See User Guide pp 3-26 – 3-28 for template information
Sybase Netezza
UPDATE tempRaw a
set deleteme = TRUE
FROM TSValues B
WHERE A.ID_TS = B.ID_TS AND A.ID_TSDate = B.ID_TSDate
AND ( ( A.Value = B.Value and A.ID_Status = B.ID_Status ) OR ( B.ID_Status >= 1 and A.ID_Status <= -1 ))
AND ( abs(A.Sigma - B.Sigma) < 0.00000001 OR A.ID_StatusSigma <= -1)
AND NOW() BETWEEN
Know Your B.ts_begin AND
Customers. B.ts_end
Grow Your AND A.Comments IS NULL;
Business.
DELETE FROM tempRaw WHERE deleteme;
• Materialized Views
• View may have only one source table
• Limited to 64 columns
• May include an ORDER BY clause
• Optimize zone maps
• Cannot include an ORGANIZE ON clause
• Sequences
• You may specify data type (byteint, smallint, int, bigint)
• Default is bigint (64 bit signed integer)
• Blocks of numbers are allocated to each SPU during execution
• Sequential number assignment cannot be assured
• General Differences
Sybase Netezza
CREATE PROCEDURE sp_TS_ProcessFillValues CREATE PROCEDURE sp_TS_ProcessFillValues
(@LoaderID int, @ID_SRC int) (INTEGER, INTEGER)
AS RETURNS INTEGER EXECUTE AS CALLER
DECLARE @err_no int, @err_msg varchar(250), LANGUAGE NZPLSQL
@CurrentTime datetime AS
begin_proc
<...procedure code ...> DECLARE
LoaderID alias for $1;
GO ID_SRC ALIAS FOR $2;
CurrentTime datetime;
Parameters are unnamed, referenced by position: EndDate datetime;
$1, $2… StartDate datetime;
Alias may be used to name parameters
begin
Procedure enclosed in a BEGIN_PROC - <... procedure code ...>
END_PROC block end;
end_proc;
Executable code enclosed in a BEGIN – END block
following declarations.
Know Your Customers. Grow Your Business.
Alternate form:
• Example
DECLARE myrec RECORD;
mytotal DOUBLE PRECISION;
BEGIN
Know
FORYour Customers.
myrec Grow*Your
IN SELECT FROMBusiness.
tsvalues LOOP
mytotal := mytotal + myrec.value;
END LOOP;
END;
to Netezza –| Prepared for Bank of America
39
Ipsos Loyalty
Introduction © 2011 Aginity LLC Ipsos, January 2007
Returning Sets from Stored Procedures
• SQLERRM
• Error message relating to last SQL error
• ROW_COUNT
• Number of rows affected by last executed SQL statement
• QUOTE_LITERAL(<expression>)
• Used when building EXECUTE IMMEDIATE strings
• Converts the value of the expression into a properly formatted literal string
• Escapes any special characters as necessary.
• QUOTE_IDENT(<expression>)
• Used when building EXECUTE IMMEDIATE strings
• Converts expression into properly formatted database object name string
• Mainly used for delimited
Know identifiers
Your Customers. Grow Your Business.
\\crpnycnaf00n2\ReconDQ\Netezza\Manuals