TDengine/tests/army/query/joinConst/inner.now.csv
Pan Wei 0cb0e109a7
enh: add more cases for constant join (#30225)
* fix: add more cases and fix issues

* enh: add more test cases

* enh: add more test cases

* fix: memory leak issue

* enh: add view cases and fix order by issue

* enh: add document description
2025-03-19 16:50:44 +08:00

19 KiB

1taos> use test;
2Database changed.
3taos> select * from a1 a join (select now as ts, f, g, 'a' from b1) b on a.ts = b.ts;
4taos> select * from a1 a join (select now as ts1, f, g, 'a' from b1) b on a.ts = b.ts1;
5taos> select a.* from a1 a join (select now as ts, f, g, 'a' from b1) b on a.ts = b.ts;
6taos> select b.* from a1 a join (select now as ts, f, g, 'a' from b1) b on a.ts = b.ts;
7taos> select b.* from a1 a join (select now as ts1, f, g, 'a' from b1) b on a.ts = b.ts1;
8taos> select a.*, b.ts from a1 a join (select now as ts1,ts, f, g, 'a' from b1) b on a.ts = b.ts1;
9taos> select b.c from a1 a join (select now as ts, f, g, 'a' c from b1) b on a.ts = b.ts;
10taos> select b.ts from a1 a join (select now as ts, f, g, 'a' c from b1) b on a.ts = b.ts;
11taos> select * from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts;
12taos> select a.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts;
13taos> select b.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts;
14taos> select b.c from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts;
15taos> select a.* from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts;
16 ts | f | g |
17======================================================
18 __today__ 00:00:00.000 | 101 | 1011 |
19 __today__ 00:00:01.000 | 102 | 1012 |
20 __tomorrow__ 00:00:00.000 | 103 | 1013 |
21 __tomorrow__ 00:00:02.000 | 104 | 1014 |
22taos> select b.ts1,a.ts from a1 a join (select now as ts1, f, g, 'a' c from b1) b on b.ts1 = a.ts;
23taos> select a.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on a.ts = b.ts;
24 ts | f | g |
25======================================================
26 __today__ 00:00:00.000 | 101 | 1011 |
27 __today__ 00:00:01.000 | 102 | 1012 |
28 __tomorrow__ 00:00:00.000 | 103 | 1013 |
29 __tomorrow__ 00:00:02.000 | 104 | 1014 |
30taos> select b.c from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts;
31 c |
32======
33 a |
34 a |
35 a |
36 a |
37taos> select b.ts from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on a.ts = b.ts;
38 ts |
39==========================
40 __today__ 00:00:00.000 |
41 __today__ 00:00:01.000 |
42 __tomorrow__ 00:00:00.000 |
43 __tomorrow__ 00:00:02.000 |
44taos> select * from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts;
45taos> select a.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts;
46taos> select b.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts1 = a.ts and a.ts = b.ts;
47taos> select b.c from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts;
48taos> select b.ts from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts1 = a.ts and a.ts = b.ts;
49taos> select * from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1;
50taos> select a.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1;
51taos> select b.* from a1 a join (select now as ts1, ts, f, g, 'a' from b1) b on b.ts = a.ts and a.ts = b.ts1;
52taos> select b.c from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1;
53taos> select b.ts from a1 a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1;
54taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from a1 order by ts desc) a join (select now as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1;
55taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from a1) a join (select now() as ts1, ts, f, g, 'a' c from b1) b on b.ts = a.ts and a.ts = b.ts1;
56taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta join (select now ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb on ta.ts=tb.ts and ta.tg1=tb.tg1;
57taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2;
58taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;
59taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=now where tb.ts=now order by tb.val;
60taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta join (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>now where tb.ts>now;
61taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta join (select today() + 1d +3s ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb on ta.ts=tb.ts and ta.tg2=tb.tg2;
62 ts | val | tg2 | ts | val | tg2 |
63============================================================================================================
64 __tomorrow__ 00:00:03.000 | 204 | 2 | __tomorrow__ 00:00:03.000 | 404 | 2 |
65taos> select * from (select now as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts;
66taos> select * from (select now as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1;
67taos> select a.* from (select now as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts;
68taos> select b.* from (select now as ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts;
69taos> select b.* from (select now as ts1, f, g, 'a' from b1) b join a1 a on a.ts = b.ts1;
70taos> select b.c from (select now as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts;
71taos> select b.ts from (select now as ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts;
72taos> select * from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts;
73taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts;
74taos> select b.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts;
75taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts;
76taos> select b.ts1 from (select now as ts1, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts;
77taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on a.ts = b.ts;
78 ts | f | g |
79======================================================
80 __today__ 00:00:00.000 | 101 | 1011 |
81 __today__ 00:00:01.000 | 102 | 1012 |
82 __tomorrow__ 00:00:00.000 | 103 | 1013 |
83 __tomorrow__ 00:00:02.000 | 104 | 1014 |
84taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts;
85 c |
86======
87 a |
88 a |
89 a |
90 a |
91taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on a.ts = b.ts;
92 ts |
93==========================
94 __today__ 00:00:00.000 |
95 __today__ 00:00:01.000 |
96 __tomorrow__ 00:00:00.000 |
97 __tomorrow__ 00:00:02.000 |
98taos> select * from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts;
99taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts;
100taos> select b.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts;
101taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts;
102taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts1 = a.ts and a.ts = b.ts;
103taos> select * from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1;
104taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1;
105taos> select b.* from (select now as ts1, ts, f, g, 'a' from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1;
106taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1;
107taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from b1) b join a1 a on b.ts = a.ts and a.ts = b.ts1;
108taos> select * from (select now ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta on ta.ts=tb.ts and ta.tg1=tb.tg1;
109taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2;
110taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;;
111taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=now where tb.ts=now order by tb.val;
112taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb join (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta on ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>now where tb.ts>now;
113taos> select * from a1 a , (select now as ts, f, g, 'a' from b1) b where a.ts = b.ts;
114taos> select * from a1 a , (select now as ts1, f, g, 'a' from b1) b where a.ts = b.ts1;
115taos> select a.* from a1 a , (select now as ts, f, g, 'a' from b1) b where a.ts = b.ts;
116taos> select b.* from a1 a , (select now as ts, f, g, 'a' from b1) b where a.ts = b.ts;
117taos> select b.c from a1 a , (select now as ts, f, g, 'a' c from b1) b where a.ts = b.ts;
118taos> select b.ts from a1 a , (select now as ts, f, g, 'a' c from b1) b where a.ts = b.ts;
119taos> select b.ts1 from a1 a , (select now as ts1, f, g, 'a' c from b1) b where a.ts = b.ts1;
120taos> select * from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts;
121taos> select a.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts;
122taos> select b.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts;
123taos> select b.c from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts;
124taos> select b.ts1 from a1 a , (select now as ts1, f, g, 'a' c from b1) b where b.ts1 = a.ts;
125taos> select a.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where a.ts = b.ts;
126 ts | f | g |
127======================================================
128 __today__ 00:00:00.000 | 101 | 1011 |
129 __today__ 00:00:01.000 | 102 | 1012 |
130 __tomorrow__ 00:00:00.000 | 103 | 1013 |
131 __tomorrow__ 00:00:02.000 | 104 | 1014 |
132taos> select b.c from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts;
133 c |
134======
135 a |
136 a |
137 a |
138 a |
139taos> select b.ts from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where a.ts = b.ts;
140 ts |
141==========================
142 __today__ 00:00:00.000 |
143 __today__ 00:00:01.000 |
144 __tomorrow__ 00:00:00.000 |
145 __tomorrow__ 00:00:02.000 |
146taos> select * from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts;
147taos> select a.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts;
148taos> select b.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts1 = a.ts and a.ts = b.ts;
149taos> select b.c from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts;
150taos> select b.ts from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts1 = a.ts and a.ts = b.ts;
151taos> select * from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1;
152taos> select a.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1;
153taos> select b.* from a1 a , (select now as ts1, ts, f, g, 'a' from b1) b where b.ts = a.ts and a.ts = b.ts1;
154taos> select b.c from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1;
155taos> select b.ts from a1 a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1;
156taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from a1) a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1;
157taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from a1 order by ts) a , (select now as ts1, ts, f, g, 'a' c from b1) b where b.ts = a.ts and a.ts = b.ts1;
158taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta , (select now ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb where ta.ts=tb.ts and ta.tg1=tb.tg1;
159taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta , (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2;
160taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;
161taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=now order by tb.val;
162taos> select * from (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta , (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>now ;
163taos> select * from (select now as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts;
164taos> select * from (select now as ts1, f, g, 'a' from b1) b , a1 a where a.ts = b.ts1;
165taos> select a.* from (select now as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts;
166taos> select b.* from (select now as ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts;
167taos> select b.c from (select now as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts;
168taos> select b.ts from (select now as ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts;
169taos> select b.ts1 from (select now as ts1, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts1;
170taos> select * from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts;
171taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts;
172taos> select b.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts;
173taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts;
174taos> select b.ts1 from (select now as ts1, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts;
175taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where a.ts = b.ts;
176 ts | f | g |
177======================================================
178 __today__ 00:00:00.000 | 101 | 1011 |
179 __today__ 00:00:01.000 | 102 | 1012 |
180 __tomorrow__ 00:00:00.000 | 103 | 1013 |
181 __tomorrow__ 00:00:02.000 | 104 | 1014 |
182taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts;
183 c |
184======
185 a |
186 a |
187 a |
188 a |
189taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where a.ts = b.ts;
190 ts |
191==========================
192 __today__ 00:00:00.000 |
193 __today__ 00:00:01.000 |
194 __tomorrow__ 00:00:00.000 |
195 __tomorrow__ 00:00:02.000 |
196taos> select * from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts;
197taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts;
198taos> select b.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts;
199taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts;
200taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts1 = a.ts and a.ts = b.ts;
201taos> select * from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1;
202taos> select a.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1;
203taos> select b.* from (select now as ts1, ts, f, g, 'a' from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1;
204taos> select b.c from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1;
205taos> select b.ts from (select now as ts1, ts, f, g, 'a' c from b1) b , a1 a where b.ts = a.ts and a.ts = b.ts1;
206taos> select * from (select now ts, last(f) val, tg1 from stb where tg1 >= 0 partition by tg1 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg1 from sta where tg1=1 partition by tg1 order by ts) ta where ta.ts=tb.ts and ta.tg1=tb.tg1;
207taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2;
208taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 order by tb.val;
209taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts=now order by tb.val;
210taos> select * from (select now ts, last(f) val, tg2 from stb where tg2 >= 0 partition by tg2 interval(1s) order by ts desc) tb , (select last(ts) as `ts`,last(f) as `val`,tg2 from sta where tg2>0 partition by tg2 interval(1s) order by ts) ta where ta.ts=tb.ts and ta.tg2=tb.tg2 and tb.ts>now ;