@@ -449,9 +449,10 @@ static int32_t tBindInfoCompare(const void *p1, const void *p2, const void *para
449
449
* `infoSorted` is whether the bind information is sorted by column id
450
450
* `pTSchema` is the schema of the table
451
451
* `rowArray` is the array to store the rows
452
+ * `orderedDup` is an array to store ordered and duplicateTs
452
453
*/
453
454
int32_t tRowBuildFromBind (SBindInfo * infos , int32_t numOfInfos , bool infoSorted , const STSchema * pTSchema ,
454
- SArray * rowArray ) {
455
+ SArray * rowArray , bool * orderedDup ) {
455
456
if (infos == NULL || numOfInfos <= 0 || numOfInfos > pTSchema -> numOfCols || pTSchema == NULL || rowArray == NULL ) {
456
457
return TSDB_CODE_INVALID_PARA ;
457
458
}
@@ -469,6 +470,7 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted,
469
470
return terrno ;
470
471
}
471
472
473
+ SRowKey rowKey , lastRowKey ;
472
474
for (int32_t iRow = 0 ; iRow < numOfRows ; iRow ++ ) {
473
475
taosArrayClear (colValArray );
474
476
@@ -507,6 +509,24 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted,
507
509
code = terrno ;
508
510
goto _exit ;
509
511
}
512
+
513
+ if (orderedDup ) {
514
+ tRowGetKey (row , & rowKey );
515
+ if (iRow == 0 ) {
516
+ // init to ordered by default
517
+ orderedDup [0 ] = true;
518
+ // init to non-duplicate by default
519
+ orderedDup [1 ] = false;
520
+ } else {
521
+ // no more compare if we already get disordered or duplicate rows
522
+ if (orderedDup [0 ] && !orderedDup [1 ]) {
523
+ int32_t code = tRowKeyCompare (& rowKey , & lastRowKey );
524
+ orderedDup [0 ] = (code >= 0 );
525
+ orderedDup [1 ] = (code == 0 );
526
+ }
527
+ }
528
+ lastRowKey = rowKey ;
529
+ }
510
530
}
511
531
512
532
_exit :
@@ -3235,9 +3255,10 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3
3235
3255
* `infoSorted` is whether the bind information is sorted by column id
3236
3256
* `pTSchema` is the schema of the table
3237
3257
* `rowArray` is the array to store the rows
3258
+ * `orderedDup` is an array to store ordered and duplicateTs
3238
3259
*/
3239
3260
int32_t tRowBuildFromBind2 (SBindInfo2 * infos , int32_t numOfInfos , bool infoSorted , const STSchema * pTSchema ,
3240
- SArray * rowArray ) {
3261
+ SArray * rowArray , bool * orderedDup ) {
3241
3262
if (infos == NULL || numOfInfos <= 0 || numOfInfos > pTSchema -> numOfCols || pTSchema == NULL || rowArray == NULL ) {
3242
3263
return TSDB_CODE_INVALID_PARA ;
3243
3264
}
@@ -3266,6 +3287,7 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte
3266
3287
}
3267
3288
}
3268
3289
3290
+ SRowKey rowKey , lastRowKey ;
3269
3291
for (int32_t iRow = 0 ; iRow < numOfRows ; iRow ++ ) {
3270
3292
taosArrayClear (colValArray );
3271
3293
@@ -3317,6 +3339,24 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte
3317
3339
code = terrno ;
3318
3340
goto _exit ;
3319
3341
}
3342
+
3343
+ if (orderedDup ) {
3344
+ tRowGetKey (row , & rowKey );
3345
+ if (iRow == 0 ) {
3346
+ // init to ordered by default
3347
+ orderedDup [0 ] = true;
3348
+ // init to non-duplicate by default
3349
+ orderedDup [1 ] = false;
3350
+ } else {
3351
+ // no more compare if we already get disordered or duplicate rows
3352
+ if (orderedDup [0 ] && !orderedDup [1 ]) {
3353
+ int32_t code = tRowKeyCompare (& rowKey , & lastRowKey );
3354
+ orderedDup [0 ] = (code >= 0 );
3355
+ orderedDup [1 ] = (code == 0 );
3356
+ }
3357
+ }
3358
+ lastRowKey = rowKey ;
3359
+ }
3320
3360
}
3321
3361
3322
3362
_exit :
0 commit comments