Uploaded image for project: 'Apache AsterixDB'
  1. Apache AsterixDB
  2. ASTERIXDB-3087

Remove useless casts for union all

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None

    Description

      DDL:

      DROP DATAVERSE TinySocial IF EXISTS;
      CREATE DATAVERSE TinySocial;USE TinySocial;CREATE TYPE EmploymentType AS CLOSED
      {
        `organization-name` : string,
        `start-date` : date,
        `end-date` : date?
      };CREATE TYPE FacebookUserType AS CLOSED {
        id : bigint,
        alias : string,
        name : string,
        `user-since` : datetime,
        `friend-ids` : {{bigint}},
        employment : [EmploymentType]
      };CREATE TYPE FacebookMessageType AS CLOSED {
        `message-id` : bigint,
        `author-id` : bigint,
        `in-response-to` : bigint?,
        `sender-location` : point?,
        message : string
      };CREATE DATASET FacebookUsers(FacebookUserType) PRIMARY KEY id;CREATE DATASET FacebookMessages(FacebookMessageType) PRIMARY KEY `message-id`; 

       

      Query:

      USE TinySocial;
      -- Disabled for a simpler plan
      SET `compiler.sort.parallel` "false";EXPLAIN
          SELECT s.`message-id` id, object_remove(s, "in-response-to") no_in_response_to
          FROM FacebookMessages AS s
      UNION ALL
          SELECT t user
          FROM FacebookUsers t
      UNION ALL
          SELECT s.`message-id` id, object_remove(s, "author-id") no_author_id
          FROM FacebookMessages s
      ORDER BY id;
       

       

      Plan:

      ...
      -- UNION_ALL  |PARTITIONED|
        exchange
        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
          project ([$$65, $$131])
          -- STREAM_PROJECT  |PARTITIONED|
            assign [$$131] <- [cast(cast({\"id\": $$65, \"no_in_response_to\": object-remove($$s, \"in-response-to\")}))]
            -- ASSIGN  |PARTITIONED|
              exchange
              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                replicate
                -- REPLICATE  |PARTITIONED|
                  exchange
                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                    data-scan []<-[$$65, $$s] <- TinySocial.FacebookMessages
                    -- DATASOURCE_SCAN  |PARTITIONED|
                      exchange
                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                        empty-tuple-source
                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED| 
      ...

       

      The second cast in :

      assign [$$131] <- [cast(cast({\"id\": $$65, \"no_in_response_to\": object-remove($$s, \"in-response-to\")}))]

      is useless as it casts to the same type

      The issue is the ARecordType deepEqual which also compares  allPossibleAdditionalFieldNames, which is an integral part of the record type but an information used by the compiler to determine the possible fields that could exist in open part

      Attachments

        Activity

          People

            wyk Wail Y. Alkowaileet
            wyk Wail Y. Alkowaileet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: