49
Is your SQL Exadata-aware? Mauro Pagano & Carlos Sierra

Is your SQL Exadata-aware?

Embed Size (px)

Citation preview

IsyourSQLExadata-aware?

MauroPagano&CarlosSierra

WhatisExadata?

• CompletesolutiontorunOracleRDBMS• Lotsoftopshelfhardware– Thatyoucanbuyanywhere...

• Specificsoftwarecapabilities– Thatyoucan’tbuyanywhereelseJ

1/29/17 2

Very partiallistofExa-specificfeatures• Somearemoreadvertised– SmartScan(since11.1)– HybridColumnarCompression(11.2.1.2)– SmartFlashCache(11.2.1.2)– SmartFlashLog(11.2.2.4)

• Someareless– ColumnarFlashCaching(12.1.2.1.0)– SmartBlockTransfer(12.1.2.2.0)

1/29/17 3

Exadata isaF1car• ”Smart”featuressolvemanyoldissues– VerylargeI/Obandwidth

• LotsofCPUandmemoryavailable• Exadata isbasicallyasupercar

• Butdoyoudriveitatitsfullpotential?– DoyourSQLsfullyleverageExadata?

1/29/17 4

1/29/17 5

HowIdroveExadata thefirsttimeNOTICE:NextisapicofmyfirsttimewithExadata.Pleasebenice,I’mvery

sensitiveaboutit

HowmanypeopledriveExadata• Manymigrationsaredrop-in– NothingspecialtomakeSQLsmoreExa-friendly

• SQLsoftenrunmuchfaster– Hardwareisverypowerful– Exa-specificSWfeaturesenabledbydefault–Manyfeaturesrequirealmostnoconfiguration

1/29/17 6

Drivinglesson#1- Memo• SmartScanisyourfriendJ– Opensthedoortoextremelypowerfulscan– RequiresFullScanandDirectPathReads

• Thatyouspent20ytryingtoavoid!!!– Doesn’tworkforobjectsmostlyinmemory

• IMPQ,ABTC,FullDBCaching– Doesn’tworkforeveryobject

• Clustertables,IOT,orascn/rowdependencies,etc (*)

1/29/17 7

Drivinglesson#2- Memo• CBOhasnospecificintelligenceforExadata– Sameformulas,algorithmsandparams asbefore• Thatyouspent20ytweakingtoavoidfullscans

–Won’tfavorExadata featuresexplicitly(*)• MightneedalittlepushtogetmoreExa-friendly

– Exadata systemstatisticshelpabit

1/29/17 8

Exampleofsimpledrop-inAnalyticalSQLonlargedataset(Exa SWON/OFF)

select cust_gender, calendar_week_number, sum(amount_sold), sum(quantity_sold)

from countries, -- from SH schema sales_big, -- ~2.5B rows customers, -- from SH schematimes -- from SH schema

where sales_big.cust_id = customers.cust_idand sales_big.time_id = times.time_idand customers.country_id = countries.country_idand countries.country_name = 'Italy' and calendar_quarter_desc = '2001-02'

group by cust_gender, calendar_week_number;

1/29/17 9

Exadata,SmartScanOFFExadata X311.2.0.3

Exadata X212.1.0.2

1/29/17 10

Oracle12cgeneratedabetterperformingplanthan11g,regardlessof

Exadata

Exadata,SmartScanOFF,11g

1/29/17 11

Exadata,SmartScanOFF,12c

1/29/17 12

Exadata HW,SmartScanONExadata X311.2.0.3

Exadata X212.1.0.2

1/29/17 13

Exadata,SmartScanON,11g

1/29/17 14

Exadata,SmartScanON,12c

1/29/17 15

Cool,Igottodonothing!• Partiallytrue–Manyfeaturesrequirealmostnoattention– Theyjustworkandgiveyoudecentgains

• Partiallyfalse– Betteruseofsomefeaturesifyouknowthem– Usingthemrightmakessignificantdifference

1/29/17 16

1/29/17 17

Exadata,SmartScanON,SQLExa-friendly

Exadata X311.2.0.3

Exadata X212.1.0.2

1/29/17 18

1/29/17 19

Exadata,SmartScanON,12c,SQLExa-friendly

1/29/17 20

Helpthejoins• SmartScanreads/filtersdataefficiently– Butitdoesn’thelpwithjoins

• Isthereawaytowriteajoinasafilter?– Kindof,usingBloomfilterstoreducedatabeforejoin– Lessdatareturnedtocomputenodestojoin

• Trickwashinttoencouragediffjoinorder->2BF– OneBFperdimension,similartoVTidea

1/29/17 21

Doesitalwayswork?• OfcoursenotJ• Efficiencydependson– Selectivityoffiltersfromthedimensions– Amountoffalsepositives– NumberofBloomFiltersappliedonlargetable• 1BFonmanycolsvsmanyBFson1col(*)

1/29/17 22

Anotherdrop-inLargetablefilteredbylookuptable(s)

select sum(amount_sold), sum(quantity_sold)

from sales_bigwhere sales_big.cust_id in

(select cust_idfrom customers,

countries where customers.country_id = countries.country_idand countries.country_name = 'Italy' and cust_credit_limit = 15000)

1/29/17 23

X2,12c,drop-invsExa-friendlyDrop-in

Exa-friendly

1/29/17 24

Exadata,SmartScanON,SQLExa-friendly

1/29/17 25

Removethesubquery• SubqueryproduceslowNDV• Canbepre-computedandusedasfilter• Hint/*+PRECOMPUTE_SUBQUERY*/• Doesn’talwayswork– Ifthesubqueryalonetakeslongtoexecute– IfhighNDVthenSmartScandisabled(usesDPR)

1/29/17 26

Drop-in#3SimpleSQLusingcomplexpredicate

SELECT COUNT(*) FROM martin.bigtab

WHERE v1 = DECODE(CASE WHEN (CASE WHEN 'ED' IN ('ED','AIS') THEN 1

WHEN ('NA'='P' OR 'ED'='SAQ') AND v1 <> 'Y' THEN 1 ELSE 0

END = 1) THEN 'X'ELSE 'N'

END ,'X','0001161826', 'Y')

1/29/17 27

'0001161826'

12c,drop-invsExa-friendlyDrop-in

Exa-friendly

1/29/17 28

cell pIO bytes eligible for pred offload 83886137344cell pIO bytes saved by storage index 0cell pIO inter bytes ret by smart scan 14740392

cell pIO bytes eligible for pred offload 83886137344cell pIO bytes saved by storage index 31303966720cell pIO inter bytes ret by smart scan 9241000

Drop-in#4SimpleSQLusinglesscomplexpredicate

SELECT COUNT(*) FROM sales_bigWHERE TO_CHAR(time_id,'YYYY-MM-DD HH24') = '1997-10-09 10'

1/29/17 29

12c,drop-invsExa-friendlyDrop-in

Exa-friendly

1/29/17 30

cell pIO bytes eligible for pred offload 103534297088cell pIO bytes saved by storage index 0cell pIO inter bytes ret by smart scan 5985839720

cell pIO bytes eligible for pred offload 103534297088cell pIO bytes saved by storage index 81859526656cell pIO inter bytes ret by smart scan 950385176

Complexfilters• CBOattemptstosimplifythemifpossible– NologictosimplifyALLofthem

• StorageIndexworkswithsimpleoperators– Complexfilterswon’tuseSI

• Simplifylogicwhenpossible• Usesuper-setfilterpredicates– Canbeoffloadedandusestorageindex– Reducenum ofrowstoapplycomplexpred on

1/29/17 31

V$SQLFN_METADATA• Listoffunctionsthatcan[not]beoffloaded– Increaseversionafterversion

• ShouldbefamiliarwhenwritingSQL• IfSQLincludesanotoffloadable then– Rewriteifpossibleusingoffloadable function– Ifnot,addsuper-setwithoffloadable function

• Specificfunctionscanbeturnedoff

1/29/17 32

Sofarwelearned• CleanyourCBOenvironment

– LettheCBOdoitsjobJ• Filtersoonertoprocesslesslater

– HelptheCBOifneeded• Appliesto

– Joins->BloomFilters– Subqueries->Unnest+BF orprecomputesubq– Complexpred ->simplifyorsuper-setpred

• Oldconcept,indexesservesamepurpose

1/29/17 33

I’mreadytoracenow!

1/29/17 34

Myfirsttimewithnotrainingwheels.

WhatifIgetanengineproblem?• Previousexamplesincreaseoffloadefficiency– It’slikegoingfasterwithafunctioningcar

• Whatisthecardoesn’tstart?– Severalconditionsdisable/impactsmartscan– Learningthemto• Avoidunexpectedsurprises• Identifywaytoalleviateimpact

1/29/17 35

Mixedload(OLTP/DW)sample

1/29/17 36

DWloadsample

1/29/17 37

SmartScanpartypoopers• Requirementsnotmet– NoFullScan+DPR,mostlycached,etc

• Notavailable– Cluster,IOT,rowscn,etc

• Rowsneedresolutionincomputenode– Chainedrowswithrowpiece indifferentAU– Consistentreadsnothelpedbyminscn cache– SaturatedcellsshippingdatatobalanceCPU

1/29/17 38

Drop-insurprise#1SQLdoesn’tuseSmartScanoneverypartition

1/29/17 39

Drop-insurprise#1SQLdoesn’tuseSmartScanoneverypartition

1/29/17 40

Drop-insurprise#1• Segment(s)toosmallforSmartScan– Legacyheavypartitioningtoextremeoftinyparts– Canalsohappenasconsequenceofcompression

• Confirmedbynsmtio traceSqlId = 9rxuuptqp3ru2, phv = 2502846130, Part# = 1NSMTIO: kcbism: islarge 1 next 0 nblks 915656 ...…NSMTIO: qertbFetch:[MTT < OBJECT_SIZE < VLOT]:…NSMTIO: kcbdpc:DirectRead

SqlId = 1vrwjrfzxmknd, phv = 2502846130, Part# = 2NSMTIO: kcbism: islarge 0 next 0 nblks 836 ……NSMTIO: qertbFetch:NoDirectRead:[- STT < OBJECT_SIZE < MTT]

1/29/17 41

Drop-insurprise#2

1/29/17 42

SmartScanspending65%onsingleblockreads

Drop-insurprise#2• Usuallybecauseof

– LargeUPDcausingchainedrows– Tableswith>255colsindifferentAU

• Chainedrowsareprocessed– Inthecellifnextpieceavailable(lesslikely)

• chained rows processed by cell– Inthecomputenodeifnot(morelikely)

• chained rows skipped by cell• Somefixes(e.g.9373758)trytominimizeimpact

1/29/17 43

Drop-insurprise#3CRneeded,returningdatatocomputenode

-------------------------------------------------------------------------------------------------------SID @INST, USERNAME , TYPE, STATISTIC , DELTA-------------------------------------------------------------------------------------------------------1497 @1, EO00 , STAT, cell physical IO interconnect bytes , 650748816 1497 @1, EO00 , STAT, cell physical IO bytes eligible for predicate offload , 612196352 1497 @1, EO00 , STAT, cell physical IO interconnect bytes returned by smart scan, 613436648 1497 @1, EO00 , STAT, cell blocks processed by cache layer , 76033 1497 @1, EO00 , STAT, cell commit cache queries , 76033

1/29/17 44

Drop-insurprise#3

• Uncommited changes– SmartScanreturnsdataneedsCRtocompute

• NotExadata specific– Justpushworkbacktocompute

• Forcommited changesMINSCNcachehelps– cell blocks helped by minscn optimization

1/29/17 45

Conclusion• Drop-inmigrationoftensub-optimallyuseExadata• LegacySQLsmayneedadjustments:

– TofullyleverageExadata features– ToimproveareaswhereExadata doesn’tautomaticallyhelp

• Mostoftheadjustmentsaresimple:– CleanCBOenvironment– Streamlinefilterpredicates

• SometimesCBOneedsalittlepush• GetfamiliarwithSmartScandisablers

– Topredictbehaviorsandavoidsurprises

1/29/17 46

47

References• Oracle®ExadataStorageServerSoftwareUser'sGuide12cRelease1(12.1)

• Oracle®ExadataDatabaseMachineSystemOverview12cRelease1(12.1)

• ExpertOracleExadata• Google.comJ

48

ContactInformation• http://mauro-pagano.com– Email• [email protected]

– Download(s)• SQLd360vYYMM (date)• TUNAs360vYYMM (date)• PathfindervYYMM (date)

49