我们有一个表,它以属性名称和值对的形式存储用户信息。在这个表上,我们通过使用 decode 将行转换为列来创建一个视图。MAX(DECODE(attribute_name,'FirstName',attribute_Value)) FirstName
CREATE OR REPLACE FORCE VIEW vw_get_userinfo
("USER_ID", "FIRSTNAME", "LASTNAME", "USEREMAIL",
"STREET", "CITY", "STATE", "ZIPCODE", "COUNTRY")
AS
SELECT
t.user_id,
t.firstname,
t.lastname,
t.useremail,
t.street,
t.city,
t.state,
t.country
FROM (WITH
tempattributes AS (SELECT
user_id,
attribute_name,
attribute_value
FROM user_details)
SELECT
user_id,
MAX(DECODE(attribute_name, 'FirstName', attribute_value)) FirstName,
MAX(DECODE(attribute_name, 'LastName', attribute_value)) LastName,
MAX(DECODE(attribute_name, 'UserEmail', attribute_value)) UserEmail,
MAX(DECODE(attribute_name, 'Street', attribute_value)) Street,
MAX(DECODE(attribute_name, 'City', attribute_value)) City,
MAX(DECODE(attribute_name, 'State', attribute_value)) State,
MAX(DECODE(attribute_name, 'ZipCode', attribute_value)) Zipcode,
MAX(DECODE(attribute_name, 'Country', attribute_value)) Country
FROM tempattributes
GROUP BY user_id
) t
在解释计划期间,使用名字字段进行查询时会执行完整扫描。在这种情况下,基于函数的索引不适用,因为索引不适用于按函数分组。有什么方法可以在FirstName
属性上创建索引?
任何帮助,将不胜感激。