Repository: tikv/tikv
File: components/tidb_query_datatype/src/codec/table.rs (Rust)

Code before:
use crate::{
    FieldTypeTp,
    codec::{batch::LazyBatchColumnVec, data_type::ScalarValueRef},
    expr::EvalContext,
    prelude::*,
};

// handle or index id
pub const ID_LEN: usize = 8;
pub const PREFIX_LEN: usize = TABLE_PREFIX_LEN + ID_LEN /*table_id*/ + SEP_LEN;
pub const RECORD_ROW_KEY_LEN: usize = PREFIX_LEN + ID_LEN;
pub const TABLE_PREFIX: &[u8] = b"t";
pub const RECORD_PREFIX_SEP: &[u8] = b"_r";
pub const INDEX_PREFIX_SEP: &[u8] = b"_i";
pub const SEP_LEN: usize = 2;
pub const TABLE_PREFIX_LEN: usize = 1;
pub const TABLE_PREFIX_KEY_LEN: usize = TABLE_PREFIX_LEN + ID_LEN;
// the maximum len of the old encoding of index value.
pub const MAX_OLD_ENCODED_VALUE_LEN: usize = 9;

/// Flag that indicate if the index value has common handle.
pub const INDEX_VALUE_COMMON_HANDLE_FLAG: u8 = 127;
/// Flag that indicate if the index value has partition id.
pub const INDEX_VALUE_PARTITION_ID_FLAG: u8 = 126;
/// Alias for INDEX_VALUE_PARTITION_ID_FLAG when used in index keys.
pub const INDEX_KEY_PARTITION_ID_FLAG: u8 = INDEX_VALUE_PARTITION_ID_FLAG;
/// Flag that indicate if the index values has the version information.
pub const INDEX_VALUE_VERSION_FLAG: u8 = 125;
/// Flag that indicate if the index value has restored data.
pub const INDEX_VALUE_RESTORED_DATA_FLAG: u8 = crate::codec::row::v2::CODEC_VERSION;

/// Deprecated. see <https://github.com/tikv/tikv/issues/17138>
/// ID for partition column, see <https://github.com/pingcap/parser/pull/1010>
pub const EXTRA_PARTITION_ID_COL_ID: i64 = -2;

/// ID for physical table id column, see <https://github.com/tikv/tikv/issues/11888>
/// If it's a global index, it will return partition id, see <https://github.com/tikv/tikv/issues/17138>
pub const EXTRA_PHYSICAL_TABLE_ID_COL_ID: i64 = -3;

// EXTRA_COMMIT_TS_COL_ID is the column ID of column which holds the commit
// timestamp.
pub const EXTRA_COMMIT_TS_COL_ID: i64 = -5;

/// `TableEncoder` encodes the table record/index prefix.
trait TableEncoder: NumberEncoder {
    fn append_table_record_prefix(&mut self, table_id: i64) -> Result<()> {
        self.write_bytes(TABLE_PREFIX)?;
        self.write_i64(table_id)?;
        self.write_bytes(RECORD_PREFIX_SEP).map_err(Error::from)
    }


Review comment (suggestion):
The constant `INDEX_KEY_PARTITION_ID_FLAG` is defined but never used in the codebase. All code, including the new key decoding logic in `decode_int_handle_from_key`, continues to use `INDEX_VALUE_PARTITION_ID_FLAG` directly. Consider either using this new constant consistently in the key-handling code paths or removing it if it's not needed.
```suggestion

```

Code after:
use crate::{
    FieldTypeTp,
    codec::{batch::LazyBatchColumnVec, data_type::ScalarValueRef},
    expr::EvalContext,
    prelude::*,
};

// handle or index id
pub const ID_LEN: usize = 8;
pub const PREFIX_LEN: usize = TABLE_PREFIX_LEN + ID_LEN /*table_id*/ + SEP_LEN;
pub const RECORD_ROW_KEY_LEN: usize = PREFIX_LEN + ID_LEN;
pub const TABLE_PREFIX: &[u8] = b"t";
pub const RECORD_PREFIX_SEP: &[u8] = b"_r";
pub const INDEX_PREFIX_SEP: &[u8] = b"_i";
pub const SEP_LEN: usize = 2;
pub const TABLE_PREFIX_LEN: usize = 1;
pub const TABLE_PREFIX_KEY_LEN: usize = TABLE_PREFIX_LEN + ID_LEN;
// the maximum len of the old encoding of index value.
pub const MAX_OLD_ENCODED_VALUE_LEN: usize = 9;

/// Flag that indicate if the index value has common handle.
pub const INDEX_VALUE_COMMON_HANDLE_FLAG: u8 = 127;
/// Flag that indicate if the index value has partition id.
pub const INDEX_VALUE_PARTITION_ID_FLAG: u8 = 126;
/// Flag that indicate if the index values has the version information.
pub const INDEX_VALUE_VERSION_FLAG: u8 = 125;
/// Flag that indicate if the index value has restored data.
pub const INDEX_VALUE_RESTORED_DATA_FLAG: u8 = crate::codec::row::v2::CODEC_VERSION;

/// Deprecated. see <https://github.com/tikv/tikv/issues/17138>
/// ID for partition column, see <https://github.com/pingcap/parser/pull/1010>
pub const EXTRA_PARTITION_ID_COL_ID: i64 = -2;

/// ID for physical table id column, see <https://github.com/tikv/tikv/issues/11888>
/// If it's a global index, it will return partition id, see <https://github.com/tikv/tikv/issues/17138>
pub const EXTRA_PHYSICAL_TABLE_ID_COL_ID: i64 = -3;

// EXTRA_COMMIT_TS_COL_ID is the column ID of column which holds the commit
// timestamp.
pub const EXTRA_COMMIT_TS_COL_ID: i64 = -5;

/// `TableEncoder` encodes the table record/index prefix.
trait TableEncoder: NumberEncoder {
    fn append_table_record_prefix(&mut self, table_id: i64) -> Result<()> {
        self.write_bytes(TABLE_PREFIX)?;
        self.write_i64(table_id)?;
        self.write_bytes(RECORD_PREFIX_SEP).map_err(Error::from)
    }

    fn append_table_index_prefix(&mut self, table_id: i64) -> Result<()> {
        self.write_bytes(TABLE_PREFIX)?;