本次澳洲CS代写的主要内容是使用C语言实现PostgreSQL的数据类型
Introduction
PostgreSQL has an extensibility model which, among other things, provides a well-defined process for adding new data types into a PostgreSQL server.
This capability has led to the development by PostgreSQL users of a number of types (such as polygons) which have become part of the standard distribution.
It also means that PostgreSQL is the database of choice in research projects which aim to push the boundaries of what kind of data a DBMS can manage.
In this assignment, we will be adding a new data type for dealing with sets of integers.
You may implement the functions for the data type in any way you like, provided that they satisfy the semantics given below.
Note that arrays in PostgreSQL have some properties and operations that make them look a little bit like sets.
However, they are not sets and have quite different semantics to the data type that we are asking you to implement.
The process for adding new base data types in PostgreSQL is described in the following sections of the PostgreSQL documentation:
- 37.10 C-Language Functions
- 37.13 User-defined Types
- 37.14 User-defined Operators
- SQL: CREATE TYPE
- SQL: CREATE OPERATOR
- SQL: CREATE OPERATOR CLASS
Section 37.13 uses an example of a complex number type, which you can use as a starting point for defining your intSet
data type (see below). Note that the complex type is a starting point only, to give an idea on how new data types are added. Don’t be fooled into thinking that this assignment just requires you to change the name complex to intSet; the intSet type is more complex (no pun intended) than the complex number type.
There are other examples of new data types under the tutorial and contrib directories. These may or may not give you some useful ideas on how to implement the intSet
data type:
- An auto-encrypted password datatype
PG_CODE/contrib/chkpass/
- A case-insensitive character string datatype
PG_CODE/contrib/citext/
- A confidence-interval datatype
PG_CODE/contrib/seg/
Setting Up
You ought to start this assignment with a fresh copy of PostgreSQL, without any changes that you might have made for the Prac exercises (unless these changes are trivial).
Note that you only need to configure, compile, and install your PostgreSQL server once for this assignment.
All subsequent compilation takes place in the src/tutorial
directory, and only requires modification of the files there.
Once you have re-installed your PostgreSQL server, you should run the following commands:
cd PG_CODE/src/tutorial cp complex.c intset.c cp complex.source intset.source
Once you’ve made the intset
files, you should also edit the Makefile
in this directory, and add the green text to the following lines:
MODULES = complex funcs intset DATA_built = advanced.sql basics.sql complex.sql funcs.sql syscat.sql intset.sql
The rest of the work for this assignment involves editing the intset.c
and intset.source
files.
In order for the Makefile
to work properly, you must use the identifier _OBJWD_
in the intset.source
file to refer to the directory holding the compiled library.
You should never directly modify the intset.sql
file produced by the Makefile
.
If you want to use other *.c
files along with intset.c
, then you can do so, but you will need to make further changes to the Makefile
to ensure that they are compiled and linked correctly into the library.
Note that your submitted versions of intset.c
and intset.source
should not contain any references to the complex
type (because that’s not what you’re implementing).
Make sure that the comments in the program describes the code that you wrote.
Also, do not put testing queries in your intset.source; all it should do is create the new data type. Put any testing you want to do in a separate *.sql, which you don’t need to submit. And do not drop the intSet type at the end of intset.source. If you do, your data type will vanish before we have a chance to test it.