Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-71774

[CQF] Improve type safety and error messages for algebra::transport

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization

      algebra::transport takes a class with a transport() and prepare() method, with one overload per case of the PolyValue. Often we only care about a few cases, so we have a catch-all overload that handles any type.

      If you make a mistake in the type signature of any of the overloads, you might not get a compile error. It will just be dead code, and algebra::transport will call the fallback overload in that case. (Or in the case of prepare(), algebra::transport will just not call it.)

      I wonder if we can improve this by defining a Transport interface. Something like this:

      template<typename Result>
      class Transport {
      public:
          void prepare(ABT&, const ScanNode&) {}
          Result transport(ABT&, const ScanNode&) = 0;
          ...
      };
      

      Then an individual transport implementation can opt-in to better type errors like this:

      class VariableCollector : Transport<void> {
          void prepare(ABT&, const ScanNode&) override { ... }
          Result transport(ABT&, const ScanNode&) override { ... }
      };
      

      The 'override' ensures the method signatures are actually the ones the caller is expecting.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: