# What happens when a table with actions defined but without any keys defined?

**URL:** <https://forum.p4.org/t/what-happens-when-a-table-with-actions-defined-but-without-any-keys-defined/1265>\
**Category:** P4 Dev\
**Created:** [March 3, 2025, 7:50pm UTC](https://forum.p4.org/t/what-happens-when-a-table-with-actions-defined-but-without-any-keys-defined/1265 "2025-03-03T19:50:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fengkeyleaf](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@fengkeyleaf](https://forum.p4.org/u/fengkeyleaf)\
**Post date:** [March 3, 2025, 7:50pm UTC](https://forum.p4.org/t/what-happens-when-a-table-with-actions-defined-but-without-any-keys-defined/1265/1 "2025-03-03T19:50:04Z")

</div>

Hi there,

I found out [an example](https://github.com/cornell-netlab/capisce/blob/main/capisce/examples/bf4_failing/flowlet_switching_16_sized_ints.p4) that has some tables with actions defined but without keys defined, such as

```auto
  @name(".flowlet") table flowlet {
      actions = {
          lookup_flowlet_map;
      }
  }

```

When we apply this table, what will happen? It seems that it has no effect? And I ran p4-graphs to get the graph representation, which shows that p4c added a default NoAction to the table.

 ![ZxgsGeDbMq](https://us1.discourse-cdn.com/flex019/uploads/p4/original/1X/514e5e901fa513e671b8427bdea5c600381772ec.png)

Does this mean we have to explicitly set lookup\_flowlet\_map as default such that we will always invoke lookup\_flowlet\_map action with whatever packets we have? like this:

```auto
  @name(".flowlet") table flowlet {
      actions = {
          lookup_flowlet_map;
      }
       @defaultonly default_action = lookup_flowlet_map;
  }

```

One more question is what the annotation @name means?

regards,

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [March 3, 2025, 8:00pm UTC](https://forum.p4.org/t/what-happens-when-a-table-with-actions-defined-but-without-any-keys-defined/1265/2 "2025-03-03T20:00:22Z")

</div>

If a P4 table has no key fields, then it is not possible to add any entries to the table.

Thus every .apply() operation on the table will get a miss when it does a lookup.

Thus the table’s default\_action will be executed.

If the default\_action is explicitly defined in the source code, that is the table’s default\_action at the time the P4 program is loaded. If it has `const default_action`, the control plane is not allowed to change it at run time. Without the `const`, the control plane is allowed to configure the table’s default\_action at run time.

If there is no `default_action` in the table’s definition, then the language spec and p4c both define that it is the same as if you explicitly wrote `default_action = NoAction();`, so the default\_action is initially a “no op” action, but it can be modified later by the control plane.

---

<div class="post-metadata">

**Author:** ![fengkeyleaf](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@fengkeyleaf](https://forum.p4.org/u/fengkeyleaf)\
**Post date:** [March 3, 2025, 8:06pm UTC](https://forum.p4.org/t/what-happens-when-a-table-with-actions-defined-but-without-any-keys-defined/1265/3 "2025-03-03T20:06:36Z")

</div>

Thanks for your detailed explanation!
