-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathSpeedUpMatviews.pm
946 lines (812 loc) · 51.1 KB
/
SpeedUpMatviews.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
#!/usr/bin/env perl
=head1 NAME
SpeedUpMatviews.pm
=head1 SYNOPSIS
mx-run SpeedUpMatviews [options] -H hostname -D dbname -u username [-F]
this is a subclass of L<CXGN::Metadata::Dbpatch>
see the perldoc of parent class for more details.
=head1 DESCRIPTION
This patch:
- updates the materialized_phenoview and materialized_genoview to reduce indexing and speed up their underlying queries
- rebuilds single category and binary materialized views as just views
- updates trials view to exclude genotyping project folders
- drops deprecated refresh functions and removes single category and binary views from matviews tracking table
=head1 AUTHOR
Bryan Ellerbrock
=head1 COPYRIGHT & LICENSE
Copyright 2010 Boyce Thompson Institute for Plant Research
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
package SpeedUpMatviews;
use Moose;
extends 'CXGN::Metadata::Dbpatch';
has '+description' => ( default => <<'' );
This patch updates the materialized_phenoview and materialized_genoview to speed up their underlying queries (prevents joining through nd_experiment, drops indexes). Also redefines trials view to exclude genotyping trial folders
sub patch {
my $self=shift;
print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
print STDOUT "\nExecuting the SQL commands.\n";
$self->dbh->do(<<EOSQL);
--do your SQL here
-- drop and recreate phenoview with single unique index and no joining through nd_experiment
DROP MATERIALIZED VIEW IF EXISTS public.materialized_phenoview CASCADE;
CREATE MATERIALIZED VIEW public.materialized_phenoview AS
SELECT
breeding_program.project_id AS breeding_program_id,
location.value::int AS location_id,
year.value AS year_id,
trial.project_id AS trial_id,
accession.stock_id AS accession_id,
seedlot.stock_id AS seedlot_id,
stock.stock_id AS stock_id,
phenotype.phenotype_id as phenotype_id,
phenotype.cvalue_id as trait_id
FROM stock accession
LEFT JOIN stock_relationship ON accession.stock_id = stock_relationship.object_id AND stock_relationship.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'plot_of' OR cvterm.name = 'plant_of' OR cvterm.name = 'analysis_of')
LEFT JOIN stock ON stock_relationship.subject_id = stock.stock_id AND stock.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'plot' OR cvterm.name = 'plant' OR cvterm.name = 'analysis_instance')
LEFT JOIN stock_relationship seedlot_relationship ON stock.stock_id = seedlot_relationship.subject_id AND seedlot_relationship.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'seed transaction')
LEFT JOIN stock seedlot ON seedlot_relationship.object_id = seedlot.stock_id AND seedlot.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'seedlot')
LEFT JOIN nd_experiment_stock ON(stock.stock_id = nd_experiment_stock.stock_id AND nd_experiment_stock.type_id IN (SELECT cvterm_id from cvterm where cvterm.name IN ('phenotyping_experiment', 'field_layout', 'analysis_experiment')))
LEFT JOIN nd_experiment_project ON nd_experiment_stock.nd_experiment_id = nd_experiment_project.nd_experiment_id
FULL OUTER JOIN project trial ON nd_experiment_project.project_id = trial.project_id
LEFT JOIN project_relationship ON trial.project_id = project_relationship.subject_project_id AND project_relationship.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'breeding_program_trial_relationship' )
FULL OUTER JOIN project breeding_program ON project_relationship.object_project_id = breeding_program.project_id
LEFT JOIN projectprop location ON trial.project_id = location.project_id AND location.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'project location' )
LEFT JOIN projectprop year ON trial.project_id = year.project_id AND year.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'project year' )
LEFT JOIN nd_experiment_phenotype ON(nd_experiment_stock.nd_experiment_id = nd_experiment_phenotype.nd_experiment_id)
LEFT JOIN phenotype ON nd_experiment_phenotype.phenotype_id = phenotype.phenotype_id
WHERE accession.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'accession')
ORDER BY breeding_program_id, location_id, trial_id, accession_id, seedlot_id, stock.stock_id, phenotype_id, trait_id
WITH DATA;
CREATE UNIQUE INDEX unq_pheno_idx ON public.materialized_phenoview(stock_id,phenotype_id,trait_id) WITH (fillfactor=100);
ALTER MATERIALIZED VIEW materialized_phenoview OWNER TO web_usr;
-- drop and recreate genoview with single unique index and unions instead of case whens
DROP MATERIALIZED VIEW IF EXISTS public.materialized_genoview CASCADE;
CREATE MATERIALIZED VIEW public.materialized_genoview AS
SELECT stock.stock_id AS accession_id,
nd_experiment_protocol.nd_protocol_id AS genotyping_protocol_id,
genotype.genotype_id AS genotype_id,
stock_type.name AS stock_type
FROM stock
JOIN cvterm AS stock_type ON (stock_type.cvterm_id = stock.type_id AND stock_type.name = 'accession')
JOIN nd_experiment_stock ON stock.stock_id = nd_experiment_stock.stock_id
JOIN nd_experiment_protocol ON nd_experiment_stock.nd_experiment_id = nd_experiment_protocol.nd_experiment_id
JOIN nd_protocol ON nd_experiment_protocol.nd_protocol_id = nd_protocol.nd_protocol_id
JOIN nd_experiment_genotype ON nd_experiment_stock.nd_experiment_id = nd_experiment_genotype.nd_experiment_id
JOIN genotype ON genotype.genotype_id = nd_experiment_genotype.genotype_id
GROUP BY 1,2,3,4
UNION
SELECT accession.stock_id AS accession_id,
nd_experiment_protocol.nd_protocol_id AS genotyping_protocol_id,
nd_experiment_genotype.genotype_id AS genotype_id,
stock_type.name AS stock_type
FROM stock AS accession
JOIN stock_relationship ON accession.stock_id = stock_relationship.object_id AND stock_relationship.type_id IN (SELECT cvterm_id from cvterm where cvterm.name IN ('tissue_sample_of', 'plant_of', 'plot_of') )
JOIN stock ON stock_relationship.subject_id = stock.stock_id AND stock.type_id IN (SELECT cvterm_id from cvterm where cvterm.name IN ('tissue_sample', 'plant', 'plot') )
JOIN cvterm AS stock_type ON (stock_type.cvterm_id = stock.type_id)
JOIN nd_experiment_stock ON stock.stock_id = nd_experiment_stock.stock_id
JOIN nd_experiment_protocol ON nd_experiment_stock.nd_experiment_id = nd_experiment_protocol.nd_experiment_id
JOIN nd_protocol ON nd_experiment_protocol.nd_protocol_id = nd_protocol.nd_protocol_id
JOIN nd_experiment_genotype ON nd_experiment_stock.nd_experiment_id = nd_experiment_genotype.nd_experiment_id
GROUP BY 1,2,3,4 ORDER BY 1,2,3;
CREATE UNIQUE INDEX unq_geno_idx ON public.materialized_genoview(accession_id,genotype_id) WITH (fillfactor=100);
ALTER MATERIALIZED VIEW materialized_genoview OWNER TO web_usr;
-- drop and recreate all the single category matviews as just views
DROP MATERIALIZED VIEW IF EXISTS public.accessions CASCADE;
CREATE VIEW public.accessions AS
SELECT stock.stock_id AS accession_id,
stock.uniquename AS accession_name
FROM stock
WHERE stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'accession') AND is_obsolete = 'f'
GROUP BY stock.stock_id, stock.uniquename;
ALTER VIEW accessions OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.breeding_programs CASCADE;
CREATE VIEW public.breeding_programs AS
SELECT project.project_id AS breeding_program_id,
project.name AS breeding_program_name
FROM project join projectprop USING (project_id)
WHERE projectprop.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'breeding_program')
GROUP BY project.project_id, project.name;
ALTER VIEW breeding_programs OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.genotyping_protocols CASCADE;
CREATE VIEW public.genotyping_protocols AS
SELECT nd_protocol.nd_protocol_id AS genotyping_protocol_id,
nd_protocol.name AS genotyping_protocol_name
FROM nd_protocol
WHERE nd_protocol.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'genotyping_experiment')
GROUP BY public.nd_protocol.nd_protocol_id, public.nd_protocol.name;
ALTER VIEW genotyping_protocols OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.locations CASCADE;
CREATE VIEW public.locations AS
SELECT nd_geolocation.nd_geolocation_id AS location_id,
nd_geolocation.description AS location_name
FROM nd_geolocation
GROUP BY public.nd_geolocation.nd_geolocation_id, public.nd_geolocation.description;
ALTER VIEW locations OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.plants CASCADE;
CREATE VIEW public.plants AS
SELECT stock.stock_id AS plant_id,
stock.uniquename AS plant_name
FROM stock
WHERE stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant') AND is_obsolete = 'f'
GROUP BY public.stock.stock_id, public.stock.uniquename;
ALTER VIEW plants OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.plots CASCADE;
CREATE VIEW public.plots AS
SELECT stock.stock_id AS plot_id,
stock.uniquename AS plot_name
FROM stock
WHERE stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot') AND is_obsolete = 'f'
GROUP BY public.stock.stock_id, public.stock.uniquename;
ALTER VIEW plots OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.trait_components CASCADE;
CREATE VIEW public.trait_components AS
SELECT cvterm.cvterm_id AS trait_component_id,
(((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text AS trait_component_name
FROM cv
JOIN cvprop ON(cv.cv_id = cvprop.cv_id AND cvprop.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = ANY ('{object_ontology,attribute_ontology,method_ontology,unit_ontology,time_ontology}')))
JOIN cvterm ON(cvprop.cv_id = cvterm.cv_id)
JOIN dbxref USING(dbxref_id)
JOIN db ON(dbxref.db_id = db.db_id)
LEFT JOIN cvterm_relationship is_subject ON cvterm.cvterm_id = is_subject.subject_id
LEFT JOIN cvterm_relationship is_object ON cvterm.cvterm_id = is_object.object_id
WHERE is_object.object_id IS NULL AND is_subject.subject_id IS NOT NULL
GROUP BY 2,1 ORDER BY 2,1;
ALTER VIEW trait_components OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.traits CASCADE;
CREATE VIEW public.traits AS
SELECT cvterm.cvterm_id AS trait_id,
(((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text AS trait_name
FROM cv
JOIN cvprop ON(cv.cv_id = cvprop.cv_id AND cvprop.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'trait_ontology'))
JOIN cvterm ON(cvprop.cv_id = cvterm.cv_id)
JOIN dbxref USING(dbxref_id)
JOIN db ON(dbxref.db_id = db.db_id)
LEFT JOIN cvterm_relationship is_variable ON cvterm.cvterm_id = is_variable.subject_id AND is_variable.type_id = (SELECT cvterm_id FROM cvterm WHERE name = 'VARIABLE_OF')
WHERE is_variable.subject_id IS NOT NULL
GROUP BY 1,2
UNION
SELECT cvterm.cvterm_id AS trait_id,
(((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text AS trait_name
FROM cv
JOIN cvprop ON(cv.cv_id = cvprop.cv_id AND cvprop.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'composed_trait_ontology'))
JOIN cvterm ON(cvprop.cv_id = cvterm.cv_id)
JOIN dbxref USING(dbxref_id)
JOIN db ON(dbxref.db_id = db.db_id)
LEFT JOIN cvterm_relationship is_subject ON cvterm.cvterm_id = is_subject.subject_id
WHERE is_subject.subject_id IS NOT NULL
GROUP BY 1,2 ORDER BY 2;
ALTER VIEW traits OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.trials CASCADE;
CREATE VIEW public.trials AS
SELECT trial.project_id AS trial_id,
trial.name AS trial_name
FROM project breeding_program
JOIN project_relationship ON(breeding_program.project_id = object_project_id AND project_relationship.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'breeding_program_trial_relationship'))
JOIN project trial ON(subject_project_id = trial.project_id)
JOIN projectprop on(trial.project_id = projectprop.project_id)
WHERE projectprop.type_id NOT IN (SELECT cvterm.cvterm_id FROM cvterm WHERE cvterm.name::text = 'cross'::text OR cvterm.name::text = 'trial_folder'::text OR cvterm.name::text = 'folder_for_trials'::text OR cvterm.name::text = 'folder_for_crosses'::text OR cvterm.name::text = 'folder_for_genotyping_trials'::text)
GROUP BY trial.project_id, trial.name;
ALTER VIEW trials OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.trial_designs CASCADE;
CREATE VIEW public.trial_designs AS
SELECT projectprop.value AS trial_design_id,
projectprop.value AS trial_design_name
FROM projectprop
JOIN cvterm ON(projectprop.type_id = cvterm.cvterm_id)
WHERE cvterm.name = 'design'
GROUP BY projectprop.value;
ALTER VIEW trial_designs OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.trial_types CASCADE;
CREATE VIEW public.trial_types AS
SELECT cvterm.cvterm_id AS trial_type_id,
cvterm.name AS trial_type_name
FROM cvterm
JOIN cv USING(cv_id)
WHERE cv.name = 'project_type'
GROUP BY cvterm.cvterm_id;
ALTER VIEW trial_types OWNER TO web_usr;
DROP MATERIALIZED VIEW IF EXISTS public.years CASCADE;
CREATE VIEW public.years AS
SELECT projectprop.value AS year_id,
projectprop.value AS year_name
FROM projectprop
WHERE projectprop.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'project year')
GROUP BY public.projectprop.value;
ALTER VIEW years OWNER TO web_usr;
-- drop and recreate all the binary matviews as just views
CREATE VIEW public.accessionsXseedlots AS
SELECT public.materialized_phenoview.accession_id,
public.stock.stock_id AS seedlot_id
FROM public.materialized_phenoview
LEFT JOIN stock_relationship seedlot_relationship ON materialized_phenoview.accession_id = seedlot_relationship.subject_id AND seedlot_relationship.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'collection_of')
LEFT JOIN stock ON seedlot_relationship.object_id = stock.stock_id AND stock.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'seedlot')
GROUP BY public.materialized_phenoview.accession_id,public.stock.stock_id;
ALTER VIEW accessionsXseedlots OWNER TO web_usr;
CREATE VIEW public.breeding_programsXseedlots AS
SELECT public.materialized_phenoview.breeding_program_id,
public.nd_experiment_stock.stock_id AS seedlot_id
FROM public.materialized_phenoview
LEFT JOIN nd_experiment_project ON materialized_phenoview.breeding_program_id = nd_experiment_project.project_id
LEFT JOIN nd_experiment ON nd_experiment_project.nd_experiment_id = nd_experiment.nd_experiment_id AND nd_experiment.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'seedlot_experiment')
LEFT JOIN nd_experiment_stock ON nd_experiment.nd_experiment_id = nd_experiment_stock.nd_experiment_id
GROUP BY 1,2;
ALTER VIEW breeding_programsXseedlots OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXseedlots AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.stock.stock_id AS seedlot_id
FROM public.materialized_genoview
LEFT JOIN stock_relationship seedlot_relationship ON materialized_genoview.accession_id = seedlot_relationship.subject_id AND seedlot_relationship.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'collection_of')
LEFT JOIN stock ON seedlot_relationship.object_id = stock.stock_id AND stock.type_id IN (SELECT cvterm_id from cvterm where cvterm.name = 'seedlot')
GROUP BY 1,2;
ALTER VIEW genotyping_protocolsXseedlots OWNER TO web_usr;
CREATE VIEW public.plantsXseedlots AS
SELECT public.stock.stock_id AS plant_id,
public.materialized_phenoview.seedlot_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY 1,2;
ALTER VIEW plantsXseedlots OWNER TO web_usr;
CREATE VIEW public.plotsXseedlots AS
SELECT public.stock.stock_id AS plot_id,
public.materialized_phenoview.seedlot_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY 1,2;
ALTER VIEW plotsXseedlots OWNER TO web_usr;
CREATE VIEW public.seedlotsXtrait_components AS
SELECT public.materialized_phenoview.seedlot_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW seedlotsXtrait_components OWNER TO web_usr;
CREATE VIEW public.seedlotsXtraits AS
SELECT public.materialized_phenoview.seedlot_id,
public.materialized_phenoview.trait_id
FROM public.materialized_phenoview
GROUP BY 1,2;
ALTER VIEW seedlotsXtraits OWNER TO web_usr;
CREATE VIEW public.seedlotsXtrials AS
SELECT public.materialized_phenoview.seedlot_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
GROUP BY 1,2;
ALTER VIEW seedlotsXtrials OWNER TO web_usr;
CREATE VIEW public.seedlotsXtrial_designs AS
SELECT public.materialized_phenoview.seedlot_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY 1,2;
ALTER VIEW seedlotsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.seedlotsXtrial_types AS
SELECT public.materialized_phenoview.seedlot_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY 1,2;
ALTER VIEW seedlotsXtrial_types OWNER TO web_usr;
CREATE VIEW public.seedlotsXyears AS
SELECT public.materialized_phenoview.seedlot_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
GROUP BY 1,2;
ALTER VIEW seedlotsXyears OWNER TO web_usr;
CREATE VIEW public.accessionsXtraits AS
SELECT public.materialized_phenoview.accession_id,
public.materialized_phenoview.trait_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.accession_id, public.materialized_phenoview.trait_id;
ALTER VIEW accessionsXtraits OWNER TO web_usr;
CREATE VIEW public.breeding_programsXtraits AS
SELECT public.materialized_phenoview.breeding_program_id,
public.materialized_phenoview.trait_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.breeding_program_id, public.materialized_phenoview.trait_id;
ALTER VIEW breeding_programsXtraits OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXtraits AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.materialized_phenoview.trait_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
GROUP BY public.materialized_genoview.genotyping_protocol_id, public.materialized_phenoview.trait_id;
ALTER VIEW genotyping_protocolsXtraits OWNER TO web_usr;
CREATE VIEW public.locationsXtraits AS
SELECT public.materialized_phenoview.location_id,
public.materialized_phenoview.trait_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.location_id, public.materialized_phenoview.trait_id;
ALTER VIEW locationsXtraits OWNER TO web_usr;
CREATE VIEW public.plantsXtraits AS
SELECT public.stock.stock_id AS plant_id,
public.materialized_phenoview.trait_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.stock.stock_id, public.materialized_phenoview.trait_id;
ALTER VIEW plantsXtraits OWNER TO web_usr;
CREATE VIEW public.plotsXtraits AS
SELECT public.stock.stock_id AS plot_id,
public.materialized_phenoview.trait_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.stock.stock_id, public.materialized_phenoview.trait_id;
ALTER VIEW plotsXtraits OWNER TO web_usr;
CREATE VIEW public.traitsXtrials AS
SELECT public.materialized_phenoview.trait_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.trait_id, public.materialized_phenoview.trial_id;
ALTER VIEW traitsXtrials OWNER TO web_usr;
CREATE VIEW public.traitsXtrial_designs AS
SELECT public.materialized_phenoview.trait_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY public.materialized_phenoview.trait_id, trialdesign.value;
ALTER VIEW traitsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.traitsXtrial_types AS
SELECT public.materialized_phenoview.trait_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.materialized_phenoview.trait_id, trialterm.cvterm_id;
ALTER VIEW traitsXtrial_types OWNER TO web_usr;
CREATE VIEW public.traitsXyears AS
SELECT public.materialized_phenoview.trait_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.trait_id, public.materialized_phenoview.year_id;
ALTER VIEW traitsXyears OWNER TO web_usr;
CREATE VIEW public.accessionsXtrait_components AS
SELECT public.materialized_phenoview.accession_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW accessionsXtrait_components OWNER TO web_usr;
CREATE VIEW public.breeding_programsXtrait_components AS
SELECT public.materialized_phenoview.breeding_program_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW breeding_programsXtrait_components OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXtrait_components AS
SELECT public.materialized_genoview.genotyping_protocol_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW genotyping_protocolsXtrait_components OWNER TO web_usr;
CREATE VIEW public.locationsXtrait_components AS
SELECT public.materialized_phenoview.location_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW locationsXtrait_components OWNER TO web_usr;
CREATE VIEW public.plantsXtrait_components AS
SELECT public.stock.stock_id AS plant_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW plantsXtrait_components OWNER TO web_usr;
CREATE VIEW public.plotsXtrait_components AS
SELECT public.stock.stock_id AS plot_id,
trait_component.cvterm_id AS trait_component_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW plotsXtrait_components OWNER TO web_usr;
CREATE VIEW public.trait_componentsXtrials AS
SELECT trait_component.cvterm_id AS trait_component_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW trait_componentsXtrials OWNER TO web_usr;
CREATE VIEW public.trait_componentsXtrial_designs AS
SELECT trait_component.cvterm_id AS trait_component_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY 1,2;
ALTER VIEW trait_componentsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.trait_componentsXtrial_types AS
SELECT trait_component.cvterm_id AS trait_component_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY 1,2;
ALTER VIEW trait_componentsXtrial_types OWNER TO web_usr;
CREATE VIEW public.trait_componentsXyears AS
SELECT trait_component.cvterm_id AS trait_component_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
JOIN cvterm trait ON(materialized_phenoview.trait_id = trait.cvterm_id)
JOIN cvterm_relationship ON(trait.cvterm_id = cvterm_relationship.object_id AND cvterm_relationship.type_id = (SELECT cvterm_id from cvterm where name = 'contains'))
JOIN cvterm trait_component ON(cvterm_relationship.subject_id = trait_component.cvterm_id)
GROUP BY 1,2;
ALTER VIEW trait_componentsXyears OWNER TO web_usr;
-- FIX VIEWS FOR PLANTS, PLOTS, TRIAL DESIGNS AND TRIAL TYPES
CREATE VIEW public.accessionsXbreeding_programs AS
SELECT public.materialized_phenoview.accession_id,
public.materialized_phenoview.breeding_program_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.accession_id, public.materialized_phenoview.breeding_program_id;
ALTER VIEW accessionsXbreeding_programs OWNER TO web_usr;
CREATE VIEW public.accessionsXgenotyping_protocols AS
SELECT public.materialized_genoview.accession_id,
public.materialized_genoview.genotyping_protocol_id
FROM public.materialized_genoview
GROUP BY public.materialized_genoview.accession_id, public.materialized_genoview.genotyping_protocol_id;
ALTER VIEW accessionsXgenotyping_protocols OWNER TO web_usr;
CREATE VIEW public.accessionsXlocations AS
SELECT public.materialized_phenoview.accession_id,
public.materialized_phenoview.location_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.accession_id, public.materialized_phenoview.location_id;
ALTER VIEW accessionsXlocations OWNER TO web_usr;
CREATE VIEW public.accessionsXplants AS
SELECT public.materialized_phenoview.accession_id,
public.stock.stock_id AS plant_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.materialized_phenoview.accession_id, public.stock.stock_id;
ALTER VIEW accessionsXplants OWNER TO web_usr;
CREATE VIEW public.accessionsXplots AS
SELECT public.materialized_phenoview.accession_id,
public.stock.stock_id AS plot_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.materialized_phenoview.accession_id, public.stock.stock_id;
ALTER VIEW accessionsXplots OWNER TO web_usr;
CREATE VIEW public.accessionsXtrial_designs AS
SELECT public.materialized_phenoview.accession_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY public.materialized_phenoview.accession_id, trialdesign.value;
ALTER VIEW accessionsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.accessionsXtrial_types AS
SELECT public.materialized_phenoview.accession_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.materialized_phenoview.accession_id, trialterm.cvterm_id;
ALTER VIEW accessionsXtrial_types OWNER TO web_usr;
CREATE VIEW public.accessionsXtrials AS
SELECT public.materialized_phenoview.accession_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.accession_id, public.materialized_phenoview.trial_id;
ALTER VIEW accessionsXtrials OWNER TO web_usr;
CREATE VIEW public.accessionsXyears AS
SELECT public.materialized_phenoview.accession_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.accession_id, public.materialized_phenoview.year_id;
ALTER VIEW accessionsXyears OWNER TO web_usr;
CREATE VIEW public.breeding_programsXgenotyping_protocols AS
SELECT public.materialized_phenoview.breeding_program_id,
public.materialized_genoview.genotyping_protocol_id
FROM public.materialized_phenoview
JOIN public.materialized_genoview USING(accession_id)
GROUP BY public.materialized_phenoview.breeding_program_id, public.materialized_genoview.genotyping_protocol_id;
ALTER VIEW breeding_programsXgenotyping_protocols OWNER TO web_usr;
CREATE VIEW public.breeding_programsXlocations AS
SELECT public.materialized_phenoview.breeding_program_id,
public.materialized_phenoview.location_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.breeding_program_id, public.materialized_phenoview.location_id;
ALTER VIEW breeding_programsXlocations OWNER TO web_usr;
CREATE VIEW public.breeding_programsXplants AS
SELECT public.materialized_phenoview.breeding_program_id,
public.stock.stock_id AS plant_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.materialized_phenoview.breeding_program_id, public.stock.stock_id;
ALTER VIEW breeding_programsXplants OWNER TO web_usr;
CREATE VIEW public.breeding_programsXplots AS
SELECT public.materialized_phenoview.breeding_program_id,
public.stock.stock_id AS plot_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.materialized_phenoview.breeding_program_id, public.stock.stock_id;
ALTER VIEW breeding_programsXplots OWNER TO web_usr;
CREATE VIEW public.breeding_programsXtrial_designs AS
SELECT public.materialized_phenoview.breeding_program_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY public.materialized_phenoview.breeding_program_id, trialdesign.value;
ALTER VIEW breeding_programsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.breeding_programsXtrial_types AS
SELECT public.materialized_phenoview.breeding_program_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.materialized_phenoview.breeding_program_id, trialterm.cvterm_id;
ALTER VIEW breeding_programsXtrial_types OWNER TO web_usr;
CREATE VIEW public.breeding_programsXtrials AS
SELECT public.materialized_phenoview.breeding_program_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.breeding_program_id, public.materialized_phenoview.trial_id;
ALTER VIEW breeding_programsXtrials OWNER TO web_usr;
CREATE VIEW public.breeding_programsXyears AS
SELECT public.materialized_phenoview.breeding_program_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.breeding_program_id, public.materialized_phenoview.year_id;
ALTER VIEW breeding_programsXyears OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXlocations AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.materialized_phenoview.location_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
GROUP BY public.materialized_genoview.genotyping_protocol_id, public.materialized_phenoview.location_id;
ALTER VIEW genotyping_protocolsXlocations OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXplants AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.stock.stock_id AS plant_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.materialized_genoview.genotyping_protocol_id, public.stock.stock_id;
ALTER VIEW genotyping_protocolsXplants OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXplots AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.stock.stock_id AS plot_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.materialized_genoview.genotyping_protocol_id, public.stock.stock_id;
ALTER VIEW genotyping_protocolsXplots OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXtrial_designs AS
SELECT public.materialized_genoview.genotyping_protocol_id,
trialdesign.value AS trial_design_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY public.materialized_genoview.genotyping_protocol_id, trialdesign.value;
ALTER VIEW genotyping_protocolsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXtrial_types AS
SELECT public.materialized_genoview.genotyping_protocol_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.materialized_genoview.genotyping_protocol_id, trialterm.cvterm_id;
ALTER VIEW genotyping_protocolsXtrial_types OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXtrials AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.materialized_phenoview.trial_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
GROUP BY public.materialized_genoview.genotyping_protocol_id, public.materialized_phenoview.trial_id;
ALTER VIEW genotyping_protocolsXtrials OWNER TO web_usr;
CREATE VIEW public.genotyping_protocolsXyears AS
SELECT public.materialized_genoview.genotyping_protocol_id,
public.materialized_phenoview.year_id
FROM public.materialized_genoview
JOIN public.materialized_phenoview USING(accession_id)
GROUP BY public.materialized_genoview.genotyping_protocol_id, public.materialized_phenoview.year_id;
ALTER VIEW genotyping_protocolsXyears OWNER TO web_usr;
CREATE VIEW public.locationsXplants AS
SELECT public.materialized_phenoview.location_id,
public.stock.stock_id AS plant_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.materialized_phenoview.location_id, public.stock.stock_id;
ALTER VIEW locationsXplants OWNER TO web_usr;
CREATE VIEW public.locationsXplots AS
SELECT public.materialized_phenoview.location_id,
public.stock.stock_id AS plot_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.materialized_phenoview.location_id, public.stock.stock_id;
ALTER VIEW locationsXplots OWNER TO web_usr;
CREATE VIEW public.locationsXtrial_designs AS
SELECT public.materialized_phenoview.location_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY public.materialized_phenoview.location_id, trialdesign.value;
ALTER VIEW locationsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.locationsXtrial_types AS
SELECT public.materialized_phenoview.location_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.materialized_phenoview.location_id, trialterm.cvterm_id;
ALTER VIEW locationsXtrial_types OWNER TO web_usr;
CREATE VIEW public.locationsXtrials AS
SELECT public.materialized_phenoview.location_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.location_id, public.materialized_phenoview.trial_id;
ALTER VIEW locationsXtrials OWNER TO web_usr;
CREATE VIEW public.locationsXyears AS
SELECT public.materialized_phenoview.location_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.location_id, public.materialized_phenoview.year_id;
ALTER VIEW locationsXyears OWNER TO web_usr;
CREATE VIEW public.plantsXplots AS
SELECT plant.stock_id AS plant_id,
plot.stock_id AS plot_id
FROM public.materialized_phenoview
JOIN stock plot ON(public.materialized_phenoview.stock_id = plot.stock_id AND plot.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
JOIN stock_relationship plant_relationship ON plot.stock_id = plant_relationship.subject_id
JOIN stock plant ON plant_relationship.object_id = plant.stock_id AND plant.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant')
GROUP BY plant.stock_id, plot.stock_id;
ALTER VIEW plantsXplots OWNER TO web_usr;
CREATE VIEW public.plantsXtrials AS
SELECT public.stock.stock_id AS plant_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.stock.stock_id, public.materialized_phenoview.trial_id;
ALTER VIEW plantsXtrials OWNER TO web_usr;
CREATE VIEW public.plantsXtrial_designs AS
SELECT public.stock.stock_id AS plant_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY stock.stock_id, trialdesign.value;
ALTER VIEW plantsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.plantsXtrial_types AS
SELECT public.stock.stock_id AS plant_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.stock.stock_id, trialterm.cvterm_id;
ALTER VIEW plantsXtrial_types OWNER TO web_usr;
CREATE VIEW public.plantsXyears AS
SELECT public.stock.stock_id AS plant_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plant'))
GROUP BY public.stock.stock_id, public.materialized_phenoview.year_id;
ALTER VIEW plantsXyears OWNER TO web_usr;
CREATE VIEW public.plotsXtrials AS
SELECT public.stock.stock_id AS plot_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.stock.stock_id, public.materialized_phenoview.trial_id;
ALTER VIEW plotsXtrials OWNER TO web_usr;
CREATE VIEW public.plotsXtrial_designs AS
SELECT public.stock.stock_id AS plot_id,
trialdesign.value AS trial_design_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY stock.stock_id, trialdesign.value;
ALTER VIEW plotsXtrial_designs OWNER TO web_usr;
CREATE VIEW public.plotsXtrial_types AS
SELECT public.stock.stock_id AS plot_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY public.stock.stock_id, trialterm.cvterm_id;
ALTER VIEW plotsXtrial_types OWNER TO web_usr;
CREATE VIEW public.plotsXyears AS
SELECT public.stock.stock_id AS plot_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
JOIN public.stock ON(public.materialized_phenoview.stock_id = public.stock.stock_id AND public.stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'plot'))
GROUP BY public.stock.stock_id, public.materialized_phenoview.year_id;
ALTER VIEW plotsXyears OWNER TO web_usr;
CREATE VIEW public.trial_designsXtrial_types AS
SELECT trialdesign.value AS trial_design_id,
trialterm.cvterm_id AS trial_type_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY trialdesign.value, trialterm.cvterm_id;
ALTER VIEW trial_designsXtrial_types OWNER TO web_usr;
CREATE VIEW public.trial_designsXtrials AS
SELECT trialdesign.value AS trial_design_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY trialdesign.value, public.materialized_phenoview.trial_id;
ALTER VIEW trial_designsXtrials OWNER TO web_usr;
CREATE VIEW public.trial_designsXyears AS
SELECT trialdesign.value AS trial_design_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
JOIN public.projectprop trialdesign ON materialized_phenoview.trial_id = trialdesign.project_id AND trialdesign.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'design' )
GROUP BY trialdesign.value, public.materialized_phenoview.year_id;
ALTER VIEW trial_designsXyears OWNER TO web_usr;
CREATE VIEW public.trial_typesXtrials AS
SELECT trialterm.cvterm_id AS trial_type_id,
public.materialized_phenoview.trial_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY trialterm.cvterm_id, public.materialized_phenoview.trial_id;
ALTER VIEW trial_typesXtrials OWNER TO web_usr;
CREATE VIEW public.trial_typesXyears AS
SELECT trialterm.cvterm_id AS trial_type_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
JOIN projectprop trialprop ON materialized_phenoview.trial_id = trialprop.project_id AND trialprop.type_id IN (SELECT cvterm_id from cvterm JOIN cv USING(cv_id) WHERE cv.name = 'project_type' )
JOIN cvterm trialterm ON trialprop.type_id = trialterm.cvterm_id
GROUP BY trialterm.cvterm_id, public.materialized_phenoview.year_id;
ALTER VIEW trial_typesXyears OWNER TO web_usr;
CREATE VIEW public.trialsXyears AS
SELECT public.materialized_phenoview.trial_id,
public.materialized_phenoview.year_id
FROM public.materialized_phenoview
GROUP BY public.materialized_phenoview.trial_id, public.materialized_phenoview.year_id;
ALTER VIEW trialsXyears OWNER TO web_usr;
-- remove rows from matviews tracking table corresponding to single category and binary views
DELETE FROM matviews where mv_name ilike '\%x%';
DELETE FROM matviews where mv_name = 'accessions';
DELETE FROM matviews where mv_name = 'breeding_programs';
DELETE FROM matviews where mv_name = 'genotyping_projects';
DELETE FROM matviews where mv_name = 'genotyping_protocols';
DELETE FROM matviews where mv_name = 'locations';
DELETE FROM matviews where mv_name = 'plants';
DELETE FROM matviews where mv_name = 'plots';
DELETE FROM matviews where mv_name = 'seedlots';
DELETE FROM matviews where mv_name = 'trait_components';
DELETE FROM matviews where mv_name = 'traits';
DELETE FROM matviews where mv_name = 'trial_designs';
DELETE FROM matviews where mv_name = 'trial_types';
DELETE FROM matviews where mv_name = 'trials';
DELETE FROM matviews where mv_name = 'years';
-- drop matview refresh functions
DROP FUNCTION IF EXISTS refresh_materialized_views;
DROP FUNCTION IF EXISTS refresh_materialized_views_concurrently;
EOSQL
print "You're done!\n";
}
####
1; #
####