Where is the source code that performs access path selection in Postgres? - postgresql

There must be a part in the query planner of Postgres that is responsible for identifying which index to use based on various information (relation, column name, operator class/family, statistics, etc.).
I know that the source code of Postgres is available online but I would like a direct link to the part that performs the access path selection. The codebase is big and I can't find the relevant part.

The possible index access paths are found in the function create_index_paths in src/backend/optimizer/path/indxpath.c.

Related

Is it possible to prevent the reading and/or setting of a field value with DBIx Class?

I'm working in a project that uses Catalyst and DBIx::Class.
I have a requirement where, under a certain condition, users should not be able to read or set a specific field in a table (e.g. the last_name field in a list of users that will be presented and may be edited by the user).
Instead of applying the conditional logic to each part of the project where that table field is read or set, risking old or new cases where the logic is missed, is it possible to implement the logic directly in the DBIx::Class based module, to never return or change the value of that field when the condition is met?
I've been trying to find the answer, and I'm still reading, but I'm somewhat new to DBIx::Class and its documentation. Any help would be highly appreciated. Thank you!
I‘d use an around Moose method modifier on the column accessor generated by DBIC.
This won‘t be a real security solution as you can still access data without the Result class, for example when using HashRefInflator.
Same for calling get_column.
Real security would be at the database level with column level security and not allowing the database user used by the application to fetch that field.
Another solution I can think of is an additional Result class for that table that doesn‘t include the column, maybe even defaulting to it and only use the one including the column when the user has a special role.

Use filter to find sub-element of table in database (DBeaver)

I'm currently trying to list all Triggers available in a PostgreSQL database, regardless of the tables, using the DBeaver GUI.
What I would like to get looks like this:
https://ibb.co/dJZXCo
A result displaying only the Triggers category would be enough, I just want to quickly identify where the triggers are in my base.
To do so, I've tried to use global filters on the base itself, but it only filters table names.
I don't know if I can configure search depth so it includes inner elements of tables; or if there is a dedicated syntax to process the Triggers category in tables; or if the solution doesn't have anything to do with filtering.
There might be a very simple solution, but I can't seem to find it.
Thank you!

How to get column name and data type returned by a custom query in postgres?

How to get column name and data type returned by a custom query in postgres? We have inbuilt functions for table/views but not for custom queries. For more clarification I would say that I need a postgres function which will take sql string as parameter and will return colnames and their datatype.
I don't think there's any built-in SQL function which does this for you.
If you want to do this purely at the SQL level, the simplest and cheapest way is probably to CREATE TEMP VIEW AS (<your_query>), dig the column definitions out of the catalog tables, and drop the view when you're done. However, this can have a non-trivial overhead depending on how often you do it (as it needs to write view definitions to the catalogs), can't be run in a read-only transaction, and can't be done on a standby server.
The ideal solution, if it fits your use case, is to build a prepared query on the client side, and make use of the metadata returned by the server (in the form of a RowDescription message passed as part of the query protocol). Unfortunately, this depends very much on which client library you're using, and how much of this information it chooses to expose. For example, libpq will give you access to everything, whereas the JDBC driver limits you to the public methods on its ResultSetMetadata object (though you could probably pull more information from its private fields via reflection, if you're determined enough).
If you want a read-only, low-overhead, client-independent solution, then you could also write a server-side C function to prepare and describe the query via SPI. Writing and building C functions comes with a bit of a learning curve, but you can find numerous examples on PGXN, or within Postgres' own contrib modules.

find whether PS/PDS in migrated state within JCL

any way i can find whether a file is migrated state within JCL ?
i need to put condition in my jcl depending on the location of the file, like how we can refer the creation, reference, expiration date..
JCL does not have the ability to query attributes; it is merely a method of referencing where data is, or specifying criteria for creating data.
If you need this type of information, it sounds like you need a REXX procedure. REXX is the primary scripting language for IBM mainframe operating systems. (There are implementations for the LUW world.) In REXX, you have access to several items which can help you:
IGGCSI00, the Catalog Interface - this is an interface to most of the data returned by the IDCAMS LISTCAT command.
The SYSDSN() function, which is a quick way of determining whether or not a data set exists (along with a few extra status values)
The LISTDSI() function, which once you validate with SYSDSN(), retrieves many different pieces of information about a data set. Most of what you are looking for is there.
IGGCSI00 is documented in the DFSMS Managing Catalogs book, in the chapter called "Catalog Search Interface User's Guide". The other two are documented in the "TSO/E REXX Reference."

Qualified naming

I'm currently doing some maintenance on an application and I've come across a big issue regarding the qualified name in tsql. I wondering if someone could clear my confusion up for me.
From my understanding you want to use USE [DatabaseName] to declare which database you are using. I notice if u "rename" the databse it automatically updates these references in your code.
However, the developer who originally wrote this code used the USE [DatabaseName]. Then in later statements he wrote: SELECT * FROM [DatabaseName].[dbo].[Table]. Well this obviously breaks if I change the Database's name. From what i've read you want to qualify names only to the owner such as: [dbo].[TableName] so it knows where to look which increases performance.
Is there a reason he included the Database name in each statement?
From what i've read you want to qualify names only to the owner such as: [dbo].[TableName] so it knows where to look which increases performance.
Not that I'm aware of, rather it looks like someone is lazy.
I always use the three name format (unless accessing a linked server instance, then it's four).
The benefit is that the correct table from the correct database & schema will be used without concern for an errant USE [appropriate database] statement. As long as the object exists, and the permissions are valid based on the need, you can recreate a stored procedure, function, view, etc in other databases without needing to address the USE [appropriate database] statement each time.
But I'm working with data spread over numerous databases on the same instance. I wouldn't have necessarily designed it that way, but it wouldn't change that I use three (or four) part qualified name format.