直接分别执行select count(*) from T partition(分区名称) where A=‘a’不就知道在哪了吗?

解决方案 »

  1.   

    哈希分区表属于散列分区,还真不好确定属于哪个分区
    不知道能不能获取分区的物理存储范围,然后根据rowid的信息进行查找
    rowid由file# block# row#组成,占用6个bytes的空间,10 bit 的 file# ,22bit 的 block# ,16 bit 的 row#
    最简单的方式是写个函数,调用就可以了
    FUNCTION GetPartition(P_A IN VARCHAR2) RETURN varchar2 IS
    i number;
    BEGIN
      select count(1) into i from T partition(part_1) where A=P_A and rownum=1;
      if i>0 then
       return 'part_1';
      end if;
      select count(1) into i from T partition(part_2) where A=P_A and rownum=1;
      if i>0 then
       return 'part_2';
      end if;
      select count(1) into i from T partition(part_3) where A=P_A and rownum=1;
      if i>0 then
       return 'part_3';
      end if;
      return null;
    END;
      

  2.   

    user_segments配合对rowid的解析,应该也能实现,但是实现起来比这个麻烦多了
      

  3.   

    HASH分区,字段的列值是按照HASH分配到HASH分区中的
    可以直接查询具体的分区
    字段是很多,但是分区个数是不多的,如你的例子,就才3个分区