SlideShare a Scribd company logo
1 of 9
HOW TO
<今日
PostgreSQLアンカンファレンス@東京
2015/05/30 (土)
河原 翔
=> CREATE TABLE test AS SELECT
generate_series('2014-05-30 00:00:00'::timestamp,
'2015-05-30 23:59:59',
'1 second') col1;
=> SELECT count(*) FROM test WHERE col1 < '2015-05-30';
count
----------
31536000
=> SELECT count(*) FROM test WHERE col1 >= '2015-05-30';
count
-------
86400
=# SELECT now();
now
-------------------------------
2015-05-30 11:49:25.454168+09
前準備
=> SELECT count(*) FROM test WHERE
to_char(col1, 'YYYYMMDD') <
to_char(now(),'YYYYMMDD');
count
----------
31536000
時間: 42716.271 ms
Aggregate (cost=798723.00..798723.01 rows=1 width=0)
-> Seq Scan on test
(cost=0.00..772371.00 rows=10540800 width=0)
Filter: (to_char(col1, 'YYYYMMDD'::text) <
to_char(now(), 'YYYYMMDD'::text))
< to_char(now(),'YYYYMMDD')
=> SELECT count(*) FROM test WHERE col1 < CURRENT_DATE;
count
----------
31536000
時間: 13180.751 ms
Aggregate (cost=772191.53..772191.54 rows=1 width=0)
-> Seq Scan on test
(cost=0.00..693315.00 rows=31550610 width=0)
Filter: (col1 < ('now'::cstring)::date)
< CURRENT_DATE
=> SELECT count(*) FROM test WHERE
col1 < date_trunc('day',now());
count
----------
31536000
時間: 12536.489 ms
Aggregate (cost=772122.00..772122.01 rows=1 width=0)
-> Seq Scan on test
(cost=0.00..693315.00 rows=31522801 width=0)
Filter: (col1 < date_trunc('day'::text, now()))
< date_trunc('day',now())
=> WITH today AS (SELECT date_trunc('day',now()))
SELECT count(*) FROM test WHERE col1 < (TABLE today);
count
----------
31536000
時間: 5931.524 ms
Aggregate (cost=561555.04..561555.05 rows=1 width=0)
CTE today
-> Result (cost=0.00..0.01 rows=1 width=0)
InitPlan 2 (returns $1)
-> CTE Scan on today (cost=0.00..0.02 rows=1 width=8)
-> Seq Scan on test
(cost=0.00..535203.00 rows=10540800 width=0)
Filter: (col1 < $1)
WITH
=> SELECT count(*) FROM test WHERE col1 < 'today'::date;
count
----------
31536000
時間: 3665.628 ms
Aggregate (cost=614079.53..614079.54 rows=1 width=0)
-> Seq Scan on test
(cost=0.00..535203.00 rows=31550610 width=0)
Filter: (col1 < '2015-05-30'::date)
< 'today'::date
=> CREATE VIEW tview AS SELECT count(*) FROM test WHERE
col1 < 'today'::date;
=> SELECT definition FROM pg_views WHERE
viewname = 'tview';
-[ RECORD 1 ]-----------------------------------------
definition | SELECT count(*) AS count
| FROM test
| WHERE (test.col1 < '2015-05-30'::date);
※「'today'::date」部がviewが作成された日付固定になってしまう
【注意】'today'::dateはview不可
=> CREATE INDEX ON test(col1);
=> SELECT
(SELECT count(*) FROM test) -
(SELECT count(*) FROM test WHERE
col1 >= 'today'::date) count;
count
----------
31536000
時間: 2259.013 ms
※「SELECT count(*) FROM test WHERE col1 < 'today'::date」では
INDEXは利用されない
【参考】INDEX

More Related Content

What's hot

Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14stewashton
 
Push And Pull Production Systems Chap7 Ppt)
Push And Pull Production Systems   Chap7 Ppt)Push And Pull Production Systems   Chap7 Ppt)
Push And Pull Production Systems Chap7 Ppt)3abooodi
 
Ejercicio de diseño de pavimento asfaltico
Ejercicio de diseño de pavimento asfalticoEjercicio de diseño de pavimento asfaltico
Ejercicio de diseño de pavimento asfalticoYohan Tovar
 
Row patternmatching12ctech14
Row patternmatching12ctech14Row patternmatching12ctech14
Row patternmatching12ctech14stewashton
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your networkPushpendra Tiwari
 
Graph Connect: Tuning Cypher
Graph Connect: Tuning CypherGraph Connect: Tuning Cypher
Graph Connect: Tuning CypherMark Needham
 
Linked List Implementation of Queue in C
Linked List Implementation of Queue in CLinked List Implementation of Queue in C
Linked List Implementation of Queue in CKasun Ranga Wijeweera
 
Functional programming in Swift
Functional programming in SwiftFunctional programming in Swift
Functional programming in SwiftJohn Pham
 
Ranges, ranges everywhere (Oracle SQL)
Ranges, ranges everywhere (Oracle SQL)Ranges, ranges everywhere (Oracle SQL)
Ranges, ranges everywhere (Oracle SQL)Stew Ashton
 
Oracle 12c SQL: Date Ranges
Oracle 12c SQL: Date RangesOracle 12c SQL: Date Ranges
Oracle 12c SQL: Date RangesStew Ashton
 
2.5 function transformations
2.5 function transformations2.5 function transformations
2.5 function transformationshisema01
 
two dimensional array
two dimensional array two dimensional array
two dimensional array Tariq Aziz
 
Presentation topic is stick data structure
Presentation topic is stick data structurePresentation topic is stick data structure
Presentation topic is stick data structureAizazAli21
 
{co/contr} variance from LSP
{co/contr} variance  from LSP{co/contr} variance  from LSP
{co/contr} variance from LSPRuslan Shevchenko
 
Week 10 part 1 pe 6282 Block Diagrams
Week  10 part 1 pe 6282   Block DiagramsWeek  10 part 1 pe 6282   Block Diagrams
Week 10 part 1 pe 6282 Block DiagramsCharlton Inao
 

What's hot (20)

Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
 
Push And Pull Production Systems Chap7 Ppt)
Push And Pull Production Systems   Chap7 Ppt)Push And Pull Production Systems   Chap7 Ppt)
Push And Pull Production Systems Chap7 Ppt)
 
Ejercicio de diseño de pavimento asfaltico
Ejercicio de diseño de pavimento asfalticoEjercicio de diseño de pavimento asfaltico
Ejercicio de diseño de pavimento asfaltico
 
Row patternmatching12ctech14
Row patternmatching12ctech14Row patternmatching12ctech14
Row patternmatching12ctech14
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your network
 
algorithmdivs
algorithmdivsalgorithmdivs
algorithmdivs
 
Graph Connect: Tuning Cypher
Graph Connect: Tuning CypherGraph Connect: Tuning Cypher
Graph Connect: Tuning Cypher
 
Linked List Implementation of Queue in C
Linked List Implementation of Queue in CLinked List Implementation of Queue in C
Linked List Implementation of Queue in C
 
Debugging TV Frame 0x24
Debugging TV Frame 0x24Debugging TV Frame 0x24
Debugging TV Frame 0x24
 
Functional programming in Swift
Functional programming in SwiftFunctional programming in Swift
Functional programming in Swift
 
Ranges, ranges everywhere (Oracle SQL)
Ranges, ranges everywhere (Oracle SQL)Ranges, ranges everywhere (Oracle SQL)
Ranges, ranges everywhere (Oracle SQL)
 
Oracle 12c SQL: Date Ranges
Oracle 12c SQL: Date RangesOracle 12c SQL: Date Ranges
Oracle 12c SQL: Date Ranges
 
Queue
QueueQueue
Queue
 
2.5 function transformations
2.5 function transformations2.5 function transformations
2.5 function transformations
 
two dimensional array
two dimensional array two dimensional array
two dimensional array
 
Presentation topic is stick data structure
Presentation topic is stick data structurePresentation topic is stick data structure
Presentation topic is stick data structure
 
{co/contr} variance from LSP
{co/contr} variance  from LSP{co/contr} variance  from LSP
{co/contr} variance from LSP
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
Les06 Subqueries
 
Week 10 part 1 pe 6282 Block Diagrams
Week  10 part 1 pe 6282   Block DiagramsWeek  10 part 1 pe 6282   Block Diagrams
Week 10 part 1 pe 6282 Block Diagrams
 
Exp 3
Exp 3Exp 3
Exp 3
 

Viewers also liked

generate_series関数使い込み
generate_series関数使い込みgenerate_series関数使い込み
generate_series関数使い込みkawarasho
 
NW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用についてNW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用についてkawarasho
 
Prosman modul-iv
Prosman modul-ivProsman modul-iv
Prosman modul-ivcherenchay
 
Tema 4: EL GOVERN DE CATALUNYA
Tema 4: EL GOVERN DE CATALUNYATema 4: EL GOVERN DE CATALUNYA
Tema 4: EL GOVERN DE CATALUNYAmonicaabellapuges
 
Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.
Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.
Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.monicaabellapuges
 
Tema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYA
Tema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYATema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYA
Tema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYAmonicaabellapuges
 
Gizi seimbang untuk_keluarga
Gizi seimbang untuk_keluargaGizi seimbang untuk_keluarga
Gizi seimbang untuk_keluargaMaria Dewi
 
Pointofsale
PointofsalePointofsale
Pointofsale01689joe
 

Viewers also liked (15)

Toluca laptop Program
Toluca laptop ProgramToluca laptop Program
Toluca laptop Program
 
egg tart
egg tartegg tart
egg tart
 
Tema 1 medi: El relleu
Tema 1 medi: El relleuTema 1 medi: El relleu
Tema 1 medi: El relleu
 
Els animals 8
Els animals 8Els animals 8
Els animals 8
 
Curriculum vitae
Curriculum vitaeCurriculum vitae
Curriculum vitae
 
generate_series関数使い込み
generate_series関数使い込みgenerate_series関数使い込み
generate_series関数使い込み
 
NW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用についてNW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用について
 
Les plantes 7
Les plantes 7Les plantes 7
Les plantes 7
 
Prosman modul-iv
Prosman modul-ivProsman modul-iv
Prosman modul-iv
 
Tema 4: EL GOVERN DE CATALUNYA
Tema 4: EL GOVERN DE CATALUNYATema 4: EL GOVERN DE CATALUNYA
Tema 4: EL GOVERN DE CATALUNYA
 
Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.
Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.
Tema 3: POBLACIÓ I ACTIVITAT ECONÒMICA DE CATALUNYA.
 
Tema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYA
Tema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYATema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYA
Tema 2: EL CLIMA I LA VEGETACIÓ DE CATALUNYA
 
Gizi seimbang untuk_keluarga
Gizi seimbang untuk_keluargaGizi seimbang untuk_keluarga
Gizi seimbang untuk_keluarga
 
Pointofsale
PointofsalePointofsale
Pointofsale
 
Crankshaft
CrankshaftCrankshaft
Crankshaft
 

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

HOW TO < 今日

  • 2. => CREATE TABLE test AS SELECT generate_series('2014-05-30 00:00:00'::timestamp, '2015-05-30 23:59:59', '1 second') col1; => SELECT count(*) FROM test WHERE col1 < '2015-05-30'; count ---------- 31536000 => SELECT count(*) FROM test WHERE col1 >= '2015-05-30'; count ------- 86400 =# SELECT now(); now ------------------------------- 2015-05-30 11:49:25.454168+09 前準備
  • 3. => SELECT count(*) FROM test WHERE to_char(col1, 'YYYYMMDD') < to_char(now(),'YYYYMMDD'); count ---------- 31536000 時間: 42716.271 ms Aggregate (cost=798723.00..798723.01 rows=1 width=0) -> Seq Scan on test (cost=0.00..772371.00 rows=10540800 width=0) Filter: (to_char(col1, 'YYYYMMDD'::text) < to_char(now(), 'YYYYMMDD'::text)) < to_char(now(),'YYYYMMDD')
  • 4. => SELECT count(*) FROM test WHERE col1 < CURRENT_DATE; count ---------- 31536000 時間: 13180.751 ms Aggregate (cost=772191.53..772191.54 rows=1 width=0) -> Seq Scan on test (cost=0.00..693315.00 rows=31550610 width=0) Filter: (col1 < ('now'::cstring)::date) < CURRENT_DATE
  • 5. => SELECT count(*) FROM test WHERE col1 < date_trunc('day',now()); count ---------- 31536000 時間: 12536.489 ms Aggregate (cost=772122.00..772122.01 rows=1 width=0) -> Seq Scan on test (cost=0.00..693315.00 rows=31522801 width=0) Filter: (col1 < date_trunc('day'::text, now())) < date_trunc('day',now())
  • 6. => WITH today AS (SELECT date_trunc('day',now())) SELECT count(*) FROM test WHERE col1 < (TABLE today); count ---------- 31536000 時間: 5931.524 ms Aggregate (cost=561555.04..561555.05 rows=1 width=0) CTE today -> Result (cost=0.00..0.01 rows=1 width=0) InitPlan 2 (returns $1) -> CTE Scan on today (cost=0.00..0.02 rows=1 width=8) -> Seq Scan on test (cost=0.00..535203.00 rows=10540800 width=0) Filter: (col1 < $1) WITH
  • 7. => SELECT count(*) FROM test WHERE col1 < 'today'::date; count ---------- 31536000 時間: 3665.628 ms Aggregate (cost=614079.53..614079.54 rows=1 width=0) -> Seq Scan on test (cost=0.00..535203.00 rows=31550610 width=0) Filter: (col1 < '2015-05-30'::date) < 'today'::date
  • 8. => CREATE VIEW tview AS SELECT count(*) FROM test WHERE col1 < 'today'::date; => SELECT definition FROM pg_views WHERE viewname = 'tview'; -[ RECORD 1 ]----------------------------------------- definition | SELECT count(*) AS count | FROM test | WHERE (test.col1 < '2015-05-30'::date); ※「'today'::date」部がviewが作成された日付固定になってしまう 【注意】'today'::dateはview不可
  • 9. => CREATE INDEX ON test(col1); => SELECT (SELECT count(*) FROM test) - (SELECT count(*) FROM test WHERE col1 >= 'today'::date) count; count ---------- 31536000 時間: 2259.013 ms ※「SELECT count(*) FROM test WHERE col1 < 'today'::date」では INDEXは利用されない 【参考】INDEX