Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit234731c

Browse files
committed
Add test for ordered projections
1 parentab7e0a9 commit234731c

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

‎expected/test.out‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,68 @@ select count(*) from vit where i>='1 minute'::interval;
333333
2
334334
(1 row)
335335

336+
create table stock(symbol char(5), day date, low real, high real, open real, close real);
337+
insert into stock values
338+
('AAA', '01-11-2018', 10.0, 11.0, 10.1, 10.8),
339+
('AAA', '02-11-2018', 11.0, 12.0, 11.2, 11.5),
340+
('AAA', '03-11-2018', 10.4, 10.6, 10.5, 10.4),
341+
('AAA', '04-11-2018', 11.1, 11.5, 11.2, 11.4),
342+
('AAA', '05-11-2018', 11.0, 11.3, 11.4, 11.1);
343+
select create_projection('vstock','stock',array['day','low','high','open','close'],array['symbol'],'day');
344+
create_projection
345+
-------------------
346+
347+
(1 row)
348+
349+
select vstock_refresh();
350+
vstock_refresh
351+
----------------
352+
5
353+
(1 row)
354+
355+
select avg((open+close)/2),max(high-low) from stock group by symbol;
356+
avg | max
357+
-----------------+-----
358+
10.960000038147 | 1
359+
(1 row)
360+
361+
set vops.auto_substitute_projections=on;
362+
explain (costs off) select avg((open+close)/2),max(high-low) from stock group by symbol;
363+
QUERY PLAN
364+
--------------------------
365+
HashAggregate
366+
Group Key: symbol
367+
-> Seq Scan on vstock
368+
(3 rows)
369+
370+
select avg((open+close)/2),max(high-low) from stock group by symbol;
371+
avg | max
372+
-----------------+-----
373+
10.960000038147 | 1
374+
(1 row)
375+
376+
insert into stock values
377+
('AAA', '06-11-2018', 10.1, 10.8, 10.3, 10.2),
378+
('AAA', '07-11-2018', 11.1, 11.8, 10.2, 11.4),
379+
('AAA', '08-11-2018', 11.2, 11.6, 11.4, 11.3),
380+
('AAA', '09-11-2018', 10.6, 11.1, 11.3, 10.8),
381+
('AAA', '10-11-2018', 10.7, 11.3, 10.8, 11.1);
382+
select vstock_refresh();
383+
vstock_refresh
384+
----------------
385+
5
386+
(1 row)
387+
388+
select avg((open+close)/2),max(high-low) from stock group by symbol;
389+
avg | max
390+
------------------+-----
391+
10.9200000762939 | 1
392+
(1 row)
393+
394+
set vops.auto_substitute_projections=off;
395+
select avg((open+close)/2),max(high-low) from stock group by symbol;
396+
avg | max
397+
------------------+-----
398+
10.9200000762939 | 1
399+
(1 row)
400+

‎sql/test.sql‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ insert into stock values
4242
select create_projection('vstock','stock',array['day','low','high','open','close'],array['symbol'],'day');
4343

4444
select vstock_refresh();
45-
selectavg((open+close)/2),max(high-low)from stockgroup byday;
45+
selectavg((open+close)/2),max(high-low)from stockgroup bysymbol;
4646
setvops.auto_substitute_projections=on;
47-
explain (costs off)selectavg((open+close)/2),max(high-low)from stockgroup byday;
48-
selectavg((open+close)/2),max(high-low)from stockgroup byday;
47+
explain (costs off)selectavg((open+close)/2),max(high-low)from stockgroup bysymbol;
48+
selectavg((open+close)/2),max(high-low)from stockgroup bysymbol;
4949

5050
insert into stockvalues
5151
('AAA','06-11-2018',10.1,10.8,10.3,10.2),
@@ -55,6 +55,6 @@ insert into stock values
5555
('AAA','10-11-2018',10.7,11.3,10.8,11.1);
5656
select vstock_refresh();
5757

58-
selectavg((open+close)/2),max(high-low)from stockgroup byday;
58+
selectavg((open+close)/2),max(high-low)from stockgroup bysymbol;
5959
setvops.auto_substitute_projections=off;
60-
selectavg((open+close)/2),max(high-low)from stockgroup byday;
60+
selectavg((open+close)/2),max(high-low)from stockgroup bysymbol;

‎vops.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,6 +3446,9 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
34463446
staticNode*
34473447
vops_add_literal_type_casts(Node*node,Const**consts)
34483448
{
3449+
if (node==NULL)
3450+
returnNULL;
3451+
34493452
if (IsA(node,BoolExpr))
34503453
{
34513454
ListCell*cell;
@@ -3679,9 +3682,11 @@ static void vops_explain_hook(Query *query,
36793682
list_length(query->rtable)==1&&/* do not support substitution for joins because it is not clear how to handle case when only of of joined table is substituted with parition */
36803683
params==NULL)/* do not support prepared statements yet */
36813684
{
3682-
char*select=pstrdup(queryString);
3683-
memset(select,' ',7);/* clear "explain" prefix */
3684-
vops_substitute_tables_with_projections(select,query);
3685+
char*explain=pstrdup(queryString);
3686+
char*select=strstr(explain,"select");
3687+
size_tprefix= (select!=NULL) ? (select-explain) :7;
3688+
memset(explain,' ',prefix);/* clear "explain" prefix */
3689+
vops_substitute_tables_with_projections(explain,query);
36853690
}
36863691
(void)query_tree_mutator(query,vops_expression_tree_mutator,&ctx,QTW_DONT_COPY_QUERY);
36873692

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp