Repository: tikv/tikv
File: components/tidb_query_executors/src/index_scan_executor.rs (Rust)

Code before:
        result.physical_columns[0]
            .ensure_all_decoded_for_test(&mut EvalContext::default(), &schema[0])
            .unwrap();
        assert_eq!(
            result.physical_columns[0].decoded().to_int_vec(),
            &[Some(indexed_value)],
            "Indexed column value mismatch"
        );

        // Verify handle (decoded from key, skipping partition ID)
        assert_eq!(
            result.physical_columns[1].decoded().to_int_vec(),
            &[Some(handle_value)],
            "Handle value mismatch - partition ID in key should be skipped"
        );

        // Verify partition ID (extracted from VALUE in V1)
        assert_eq!(
            result.physical_columns[2].decoded().to_int_vec(),
            &[Some(PARTITION_ID)],
            "Partition ID mismatch - should be extracted from value"
        );
    }

    #[test]
    fn test_v1_edge_cases() {
        // Test edge cases for V1 format

        const TABLE_ID: i64 = 100;
        const INDEX_ID: i64 = 5;

        // Test case 1: Zero partition ID
        {
            let columns_info = vec![
                {
                    let mut ci = ColumnInfo::default();
                    ci.set_column_id(1);
                    ci.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
                    ci
                },
                {
                    let mut ci = ColumnInfo::default();
                    ci.set_column_id(-1);
                    ci.set_pk_handle(true);
                    ci.as_mut_accessor().set_tp(FieldTypeTp::LongLong);
                    ci
                },
                {
                    let mut ci = ColumnInfo::default();
                    ci.set_column_id(table::EXTRA_PARTITION_ID_COL_ID);
                    ci.as_mut_accessor().set_tp(FieldTypeTp::LongLong);

Review comment (suggestion):
We can add a loop to `test_non_unique_global_index_v1_partition_in_key_and_value` and put zero / negative cases to a `vec!` to reduce boilerplate

Code after:
            let key = table::encode_index_seek_key(TABLE_ID, INDEX_ID, &index_key_data);

            // Build index value with partition ID (V1 still has it in value too - old
            // location)
            let mut value = vec![0u8]; // tail_len = 0 (no tail data)

            // Add partition ID to value
            value.push(table::INDEX_VALUE_PARTITION_ID_FLAG);
            let mut pid_bytes = vec![0u8; 8];
            NumberCodec::encode_i64(&mut pid_bytes, partition_id);
            value.extend(&pid_bytes);

            let key_ranges = vec![{
                let mut range = KeyRange::default();
                range.set_start(key.clone());
                range.set_end(key.clone());
                convert_to_prefix_next(range.mut_end());
                range
            }];

            let store = FixtureStorage::from(vec![(key, value)]);
            let mut executor = BatchIndexScanExecutor::<_, ApiV1>::new(
                store,
                Arc::new(EvalConfig::default()),
                columns_info.clone(),
                key_ranges,
                0, // primary_column_ids_len = 0 (non-clustered table, int handle)
                false,
                false,
                false,
                false,
            )
            .unwrap();

            let mut result = block_on(executor.next_batch(10));
            assert!(result.is_drained.as_ref().unwrap().stop());
            assert_eq!(result.physical_columns.columns_len(), 3);
            assert_eq!(result.physical_columns.rows_len(), 1);

            // Verify indexed column
            result.physical_columns[0]
                .ensure_all_decoded_for_test(&mut EvalContext::default(), &schema[0])
                .unwrap();
            assert_eq!(
                result.physical_columns[0].decoded().to_int_vec(),
                &[Some(indexed_value)],
                "Indexed column value mismatch for {}",
                test_name
            );

            // Verify handle (decoded from key, skipping partition ID)