11WITH DRepDistr AS (
22 SELECT
3- * ,
3+ drep_distr. * ,
44 ROW_NUMBER() OVER (PARTITION BY drep_hash .id ORDER BY drep_distr .epoch_no DESC ) AS rn
55 FROM
66 drep_distr
77 JOIN drep_hash ON drep_hash .id = drep_distr .hash_id
88),
99DRepActivity AS (
1010 SELECT
11- drep_activity AS drep_activity ,
12- epoch_no AS epoch_no
11+ drep_activity,
12+ epoch_no
1313 FROM
1414 epoch_param
1515 WHERE
2626 encode(va .data_hash , ' hex' ),
2727 dr_deposit .deposit ,
2828 DRepDistr .amount ,
29- (DRepActivity .epoch_no - Max (coalesce( block .epoch_no , block_first_register .epoch_no ) )) <= DRepActivity .drep_activity AS active,
29+ (DRepActivity .epoch_no - COALESCE( block .epoch_no , block_first_register .epoch_no )) <= DRepActivity .drep_activity AS active,
3030 encode(dr_voting_anchor .tx_hash , ' hex' ) AS tx_hash,
3131 newestRegister .time AS last_register_time,
3232 COALESCE(latestDeposit .deposit , 0 ),
5050 FROM
5151 drep_registration dr
5252 WHERE
53- dr .deposit IS NOT NULL ) AS dr_deposit ON dr_deposit . drep_hash_id = dh . id
54- AND dr_deposit .rn = 1
55- JOIN (
53+ dr .deposit IS NOT NULL
54+ ) AS dr_deposit ON dr_deposit . drep_hash_id = dh . id AND dr_deposit .rn = 1
55+ JOIN (
5656 SELECT
5757 dr .id ,
5858 dr .drep_hash_id ,
5959 dr .deposit ,
6060 ROW_NUMBER() OVER (PARTITION BY dr .drep_hash_id ORDER BY dr .tx_id DESC ) AS rn
6161 FROM
62- drep_registration dr) AS latestDeposit ON latestDeposit . drep_hash_id = dh . id
63- AND latestDeposit .rn = 1
62+ drep_registration dr
63+ ) AS latestDeposit ON latestDeposit . drep_hash_id = dh . id AND latestDeposit .rn = 1
6464 LEFT JOIN (
6565 SELECT
6666 dr .id ,
7070 tx .hash AS tx_hash
7171 FROM
7272 drep_registration dr
73- JOIN tx ON tx .id = dr .tx_id ) AS dr_voting_anchor ON dr_voting_anchor .drep_hash_id = dh .id
74- AND dr_voting_anchor .rn = 1
75- LEFT JOIN (
73+ JOIN tx ON tx .id = dr .tx_id
74+ WHERE
75+ dr .deposit IS NOT NULL AND dr .deposit >= 0
76+ ) AS dr_voting_anchor ON dr_voting_anchor .drep_hash_id = dh .id AND dr_voting_anchor .rn = 1
77+ LEFT JOIN (
7678 SELECT
7779 dr .id ,
7880 dr .drep_hash_id ,
8284 FROM
8385 drep_registration dr
8486 JOIN tx ON tx .id = dr .tx_id
85- WHERE dr .deposit is not null
86- AND dr .deposit >= 0 ) AS dr_non_deregister_voting_anchor ON dr_non_deregister_voting_anchor .drep_hash_id = dh .id
87- AND dr_non_deregister_voting_anchor .rn = 1
87+ ) AS dr_non_deregister_voting_anchor ON dr_non_deregister_voting_anchor .drep_hash_id = dh .id AND dr_non_deregister_voting_anchor .rn = 1
8888 LEFT JOIN (
8989 SELECT
9090 dr .id ,
9191 dr .drep_hash_id ,
9292 dr .voting_anchor_id ,
9393 ROW_NUMBER() OVER (PARTITION BY dr .drep_hash_id ORDER BY dr .tx_id DESC ) AS rn
9494 FROM
95- drep_registration dr) AS second_to_newest_drep_registration ON second_to_newest_drep_registration .drep_hash_id = dh .id
96- AND second_to_newest_drep_registration .rn = 2
97- LEFT JOIN DRepDistr ON DRepDistr .hash_id = dh .id
98- AND DRepDistr .rn = 1
95+ drep_registration dr
96+ ) AS second_to_newest_drep_registration ON second_to_newest_drep_registration .drep_hash_id = dh .id AND second_to_newest_drep_registration .rn = 2
97+ LEFT JOIN DRepDistr ON DRepDistr .hash_id = dh .id AND DRepDistr .rn = 1
9998 LEFT JOIN voting_anchor va ON va .id = dr_voting_anchor .voting_anchor_id
10099 LEFT JOIN voting_anchor non_deregister_voting_anchor ON non_deregister_voting_anchor .id = dr_non_deregister_voting_anchor .voting_anchor_id
101100 LEFT JOIN (
102- SELECT fetch_error as message, voting_anchor_id
103- FROM off_chain_vote_fetch_error
104- WHERE fetch_time = (
105- SELECT max (fetch_time)
106- FROM off_chain_vote_fetch_error)
107- GROUP BY fetch_error, voting_anchor_id
101+ SELECT
102+ fetch_error as message,
103+ voting_anchor_id
104+ FROM
105+ off_chain_vote_fetch_error
106+ WHERE
107+ fetch_time = (
108+ SELECT
109+ max (fetch_time)
110+ FROM
111+ off_chain_vote_fetch_error
112+ )
113+ GROUP BY
114+ fetch_error,
115+ voting_anchor_id
108116 ) AS fetch_error ON fetch_error .voting_anchor_id = va .id
109117 LEFT JOIN off_chain_vote_data ON off_chain_vote_data .voting_anchor_id = va .id
110- LEFT JOIN off_chain_vote_drep_data on off_chain_vote_drep_data .off_chain_vote_data_id = off_chain_vote_data .id
118+ LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data .off_chain_vote_data_id = off_chain_vote_data .id
111119 CROSS JOIN DRepActivity
112- LEFT JOIN voting_procedure AS voting_procedure ON voting_procedure .drep_voter = dh .id
113- LEFT JOIN tx AS tx ON tx .id = voting_procedure .tx_id
114- LEFT JOIN block AS block ON block .id = tx .block_id
120+ LEFT JOIN voting_procedure ON voting_procedure .drep_voter = dh .id
121+ LEFT JOIN tx ON tx .id = voting_procedure .tx_id
122+ LEFT JOIN block ON block .id = tx .block_id
115123 LEFT JOIN (
116124 SELECT
117125 block .time ,
@@ -122,16 +130,16 @@ FROM
122130 JOIN tx ON tx .id = dr .tx_id
123131 JOIN block ON block .id = tx .block_id
124132 WHERE
125- NOT (dr .deposit < 0 )) AS newestRegister ON newestRegister . drep_hash_id = dh . id
126- AND newestRegister .rn = 1
133+ NOT (dr .deposit < 0 )
134+ ) AS newestRegister ON newestRegister . drep_hash_id = dh . id AND newestRegister .rn = 1
127135 LEFT JOIN (
128136 SELECT
129137 dr .tx_id ,
130138 dr .drep_hash_id ,
131139 ROW_NUMBER() OVER (PARTITION BY dr .drep_hash_id ORDER BY dr .tx_id ASC ) AS rn
132140 FROM
133- drep_registration dr) AS dr_first_register ON dr_first_register . drep_hash_id = dh . id
134- AND dr_first_register .rn = 1
141+ drep_registration dr
142+ ) AS dr_first_register ON dr_first_register . drep_hash_id = dh . id AND dr_first_register .rn = 1
135143 LEFT JOIN tx AS tx_first_register ON tx_first_register .id = dr_first_register .tx_id
136144 LEFT JOIN block AS block_first_register ON block_first_register .id = tx_first_register .block_id
137145WHERE
@@ -142,6 +150,8 @@ WHERE
142150 off_chain_vote_drep_data .given_name ILIKE ?
143151 )
144152GROUP BY
153+ block_first_register .epoch_no ,
154+ block .epoch_no ,
145155 dh .raw ,
146156 second_to_newest_drep_registration .voting_anchor_id ,
147157 dh .view ,
@@ -163,4 +173,4 @@ GROUP BY
163173 off_chain_vote_drep_data .motivations ,
164174 off_chain_vote_drep_data .qualifications ,
165175 off_chain_vote_drep_data .image_url ,
166- off_chain_vote_drep_data .image_hash
176+ off_chain_vote_drep_data .image_hash ;
0 commit comments